flutter_cached_network_image icon indicating copy to clipboard operation
flutter_cached_network_image copied to clipboard

flexible hight inside ListView.Builder

Open bhanuka96 opened this issue 5 years ago • 9 comments

Is it possible to use flexible height inside ListView?

Now, the image is not displayed. it should add height to display

CachedNetworkImage(
                  imageBuilder: (context, imageProvider) => Container(
                    width: width,
                    decoration: BoxDecoration(
                      border: Border.all(color: Palette.greyTextColor),
                      borderRadius: BorderRadius.all(Radius.circular(8.0)),
                      image: DecorationImage(image: imageProvider, fit: BoxFit.cover),
                    ),
                  ),
                  placeholder: (context, url) => ///
                  errorWidget: (context, url, error) => ///
                  imageUrl: image,
                  fit: BoxFit.cover,
                ),

bhanuka96 avatar Sep 17 '20 09:09 bhanuka96

Did you set a height to items in the listview itself?

renefloor avatar Sep 17 '20 09:09 renefloor

Thanks for quick reply. I need to show flexible height, If I added Image.network(image), it's working. flexible height not working with CachedNetworkImage

Full code

return ListView.builder(
                  padding: EdgeInsets.only(top: 68.19, left: 5, bottom: 5),
                  itemCount: snapshot.data.length,
                  itemBuilder: (BuildContext context, int index) {
                      return CachedNetworkImage(
                        imageBuilder: (context, imageProvider) => Container(
                          width: width,
                          // height: 200.0,
                          decoration: BoxDecoration(
                            border: Border.all(color: Palette.greyTextColor),
                            borderRadius: BorderRadius.all(Radius.circular(8.0)),
                            image: DecorationImage(image: imageProvider, fit: BoxFit.cover),
                          ),
                        ),
                        placeholder: (context, url) => Container(
                          width: width,
                          // height: 200.0,
                        ),
                        errorWidget: (context, url, error) => ClipRRect(
                          borderRadius: BorderRadius.all(Radius.circular(8.0)),
                          child: Container(
                            decoration: BoxDecoration(
                              border: Border.all(color: Palette.greyTextColor),
                              borderRadius: BorderRadius.all(Radius.circular(8.0)),
                            ),
                            child: Image.asset(
                              'assets/img_not_available.jpeg',
                              width: width,
                              // height: 200.0,
                              fit: BoxFit.cover,
                            ),
                          ),
                        ),
                        imageUrl: snapshot.data[index].image,
                        fit: BoxFit.cover,
                      );
                  });

bhanuka96 avatar Sep 17 '20 09:09 bhanuka96

@renefloor can I know is it possible or not using CachedNetworkImage?

bhanuka96 avatar Sep 17 '20 13:09 bhanuka96

I'm not sure, I've never needed it myself, so I'll have to test something myself. I can imagine it is not working because the image and placeholder/error widgets are placed on a stack.

renefloor avatar Sep 18 '20 07:09 renefloor

the issue was DecorationImage. without issuing this, it's working.

imageBuilder: (context, imageProvider) => Container(
                          width: width,
                          decoration: BoxDecoration(
                            border: Border.all(color: Palette.greyTextColor),
                            borderRadius: BorderRadius.all(Radius.circular(8.0)),
                            image: DecorationImage(image: imageProvider, fit: BoxFit.cover),
                          ),
                        ),

but another issue is, without using imageBuilder. we can't add border and borderRadius. Currently, I used ClipRRect widget. but border color is not good with ClipRRect

bhanuka96 avatar Sep 18 '20 08:09 bhanuka96

Is that because of the height?

renefloor avatar Oct 08 '20 08:10 renefloor

same issue

pppshiwen avatar Jul 02 '21 03:07 pppshiwen

same issue

bebalance avatar Mar 23 '22 10:03 bebalance