抖动图像预加载 [英] Flutter image preload

查看:48
本文介绍了抖动图像预加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以以某种方式预加载应用程序上的图像开始?就像我的抽屉里有背景图像,但是第一次打开抽屉时,我可以看到图像闪烁,就像它是从资产中获取然后显示的一样,一旦我第一次看到它,就会给我带来不好的体验抽屉的开口行为正常,因为它已被缓存。我想在应用程序加载时预取它,这样就没有这种影响。

Is it possible to preload somehow the image on the app start? Like I have an background image in my drawer but for the first time when I open the drawer I can see the image blinks like it is fetched from assets and then displayed and it gives bad experience to me once I see it for the first time other openings of the drawer are behaving as expected because it is cached. I would like to prefetch it on the app load so there is no such effect.

推荐答案

使用 precacheImage 函数开始在抽屉前加载图像建成。例如,在包含抽屉的小部件中:

Use the precacheImage function to start loading an image before your drawer is built. For example, in the widget that contains your drawer:

class MyWidgetState extends State<MyWidget> {

  @override
  void initState() {
    // adjust the provider based on the image type
    precacheImage(new AssetImage('...'));
    super.initState();
  }

}

这篇关于抖动图像预加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆