如何从FadeInImage小部件中的图标中创建图像提供程序? [英] How to make an image provider from an Icon in flutter for FadeInImage widget?

查看:77
本文介绍了如何从FadeInImage小部件中的图标中创建图像提供程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将FadeInImage与图标一起用作占位符.

I want to use FadeInImage with an icon as a placeholder.

FadeInImage的构造函数很少.

在默认构造函数中,它使用ImageProvider作为占位符,在FadeInImage.MemoryNetwork(中,它使用Uint8List作为内存占位符.

In a default constructor it takes ImageProvider as a placeholder, and in FadeInImage.MemoryNetwork( it takes Uint8List as a memory placeholder.

第三个构造函数创建AssetImage,但是我怀疑这是否有用.

The third constructor creates AssetImage, but I doubt that is useful here.

是否可以将Icon转换为这些数据类型之一?

Is there any way to convert an Icon to one of those data types?

示例签名:

FadeInImage(placeholder: iconPlaceholder, image: NetworkImage("url"))

推荐答案

图标实际上只是字体中的文本,因此很难将其转换为图像. 烹饪书中的技巧应该可以起作用.使用带有图标和透明占位符的堆栈.

Icons are really just text from a font, so its tricky to make that into an image. The trick in the cookbook should work. Use a Stack with the Icon behind and a transparent placeholder.

    body: Stack(
      children: <Widget>[
        Center(child: Icon(Icons.something)),
        Center(
          child: FadeInImage.memoryNetwork(
            placeholder: kTransparentImage,
            image:
                'https://github.com/flutter/website/blob/master/_includes/code/layout/lakes/images/lake.jpg?raw=true',
          ),
        ),
      ],
    ),

这篇关于如何从FadeInImage小部件中的图标中创建图像提供程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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