如何从FadeInImage小部件中的图标中创建图像提供程序? [英] How to make an image provider from an Icon in flutter for FadeInImage widget?
问题描述
我想将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屋!