Preloading local image assets in Flutter

后端 未结 1 997
春和景丽
春和景丽 2021-01-04 03:10

I have a list of image assets, and I have one Image widget onscreen. I use a button to cycle through them, using setState().



        
1条回答
  •  花落未央
    2021-01-04 03:59

    Make sure you have gaplessPlayback set to true for your image.

    This won't solve the preloading problem, but it will prevent the image from flashing to white when switching assets.

    With gaplessPlayback set to true, your original image will remain until the new image has completed loading and no "white flash gap" will be present.

    var img = new Image.asset(
      _photoData[_coverPhoto],
      fit: ImageFit.cover,
      height: 600.0,
      gaplessPlayback: true,
    );
    

    0 讨论(0)
提交回复
热议问题