代码之家  ›  专栏  ›  技术社区  ›  GPH

列表的颤振预加载图像

  •  0
  • GPH  · 技术社区  · 7 年前

    我的flatter应用程序想通过调用image.network()显示firebase的图像。但是图像显示有点晚。 请帮忙解决这个问题。如何预先加载图像或将图像保存到缓存中?

    child: ListTile(
                    leading: Image.network(
                      food.thumbnail,
                      width: 60.0,
                    ),
                    title: Text(
                        food.foodName + "     " + '\$' + food.foodPrice.toString()),
                    subtitle: Text('編碼: ' + food.foodCode),
                    onTap: () {}),
    

    更新时间:

    child: ListTile(
                    leading:
                    Image(image: new CachedNetworkImageProvider(food.thumbnail),
                    width: 60.0,),
    
                    title: Text(
                        food.foodName + "     " + '\$' + food.foodPrice.toString()),
                    subtitle: Text('編碼: ' + food.foodCode),
                    onTap: () {}),
              ),
    

    请看我的更新,使用CachedNetworkImageProvider,图像显示也很晚。我想我弄错了。请帮忙。

    1 回复  |  直到 7 年前
        1
  •  3
  •   CopsOnRoad    7 年前

    对于这样的情况,flatter中有一个小部件,它从盒子里出来,被称为 FadeInImage

    FadeInImage(
      height: 200.0, // Change it to your need
      width: 300.0, // Change it to your need
      fit: BoxFit.cover,
      placeholder: AssetImage("assets/company_logo.jpg"),
      image: NetworkImage(your_image_url),
    ),
    

    placeHolder