Flutter_cached_network_image: 希望增加图片加载成功的回调方法

Created on 11 Apr 2019  ·  7Comments  ·  Source: Baseflow/flutter_cached_network_image

希望增加图片加载成功的回调方法
因图片未加载成功导致页面的位置被撑大.图片加载成功后,切换到别的页面回来后,页面又回到正常大小.

Callback methods that wish to add successful image loading

The position of the page is enlarged because the picture is not loaded successfully. After the picture is loaded successfully, the page returns to its normal size after switching to another page.

Most helpful comment

@lifetin You can do like this. It seems that this callback feature is not needed.

CachedNetworkImage(
              imageUrl: url,
              fit: BoxFit.cover,
              imageBuilder: (context, imageProvider) {
                Image imageView = Image(
                  image: imageProvider,
                );
                ImageStream stream =
                    imageView.image.resolve(ImageConfiguration());
                stream.addListener(ImageStreamListener(
                    (ImageInfo info, bool synchronousCall) {
                      _TileItems[index].width = info.image.width;
                      _TileItems[index].height = info.image.height;
                    }));
                return Container(
                  child: imageView,
                );
              }),

All 7 comments

add image on success callback

Not sure what you issue is. Do you want a callback on success or do you have issues with the size?

This feature is useful. I should know the image width and height when use StaggeredGridView which has a dynamic height. If I don't know the width and height it will tremble when redraw again.

@lifetin You can do like this. It seems that this callback feature is not needed.

CachedNetworkImage(
              imageUrl: url,
              fit: BoxFit.cover,
              imageBuilder: (context, imageProvider) {
                Image imageView = Image(
                  image: imageProvider,
                );
                ImageStream stream =
                    imageView.image.resolve(ImageConfiguration());
                stream.addListener(ImageStreamListener(
                    (ImageInfo info, bool synchronousCall) {
                      _TileItems[index].width = info.image.width;
                      _TileItems[index].height = info.image.height;
                    }));
                return Container(
                  child: imageView,
                );
              }),

i want too

@saviourdog doesn't the solution of @bailyzheng work for you?

@saviourdog doesn't the solution of @bailyzheng work for you?

Yes, it 's OK

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gjrjf picture gjrjf  ·  4Comments

yossefEl picture yossefEl  ·  4Comments

flutteradv picture flutteradv  ·  6Comments

ivk1800 picture ivk1800  ·  7Comments

love-bkpp picture love-bkpp  ·  5Comments