Flutter “和”的区别是什么;“图像”;及;ImageProvider";飘飘然?
有与此主题相关的答案,但它们提供了解决方法,而不是解释 为什么不能在需要ImageProvider的地方使用图像?从概念上讲,我觉得它们是一样的Flutter “和”的区别是什么;“图像”;及;ImageProvider";飘飘然?,flutter,flutter-layout,Flutter,Flutter Layout,有与此主题相关的答案,但它们提供了解决方法,而不是解释 为什么不能在需要ImageProvider的地方使用图像?从概念上讲,我觉得它们是一样的 child: new CircleAvatar( backgroundImage: NetworkImage("https..."), // works backgroundImage: Image.asset('images/image.png'), // error ), 尝试直接使用图像时产生的错误为: 错误:无法将参数类
child: new CircleAvatar(
backgroundImage: NetworkImage("https..."), // works
backgroundImage: Image.asset('images/image.png'), // error
),
尝试直接使用图像时产生的错误为:
错误:无法将参数类型“Image”分配给参数类型“ImageProvider”
图像是显示图像的小部件 相反,ImageProvider允许您识别图像,而不知道最终资产的确切位置。当有人想要读取图像时,将稍后解析资产的位置。image vs ImageProvider 图像提供程序是将图像提供给图像小部件的程序;D 图像提供者不一定就在那里有图像,但它知道如何获取图像 获取图像 如果您需要
图像
小部件,请使用以下选项之一:
Image.asset()
Image.network()
Image.file()
Image.memory()
图像提供程序
,请使用以下选项之一:
AssetImage()
NetworkImage()
FileImage()
MemoryImage()
ImageProvider
对象,并且想要一个Image
小部件,请执行以下操作:
Image(
image: myImageProvider,
)
myImageWidget.image
将图像转换为图像提供程序
如果您有一个图像
小部件,并且需要它的图像提供程序
,请执行以下操作:
Image(
image: myImageProvider,
)
myImageWidget.image
请避免使用新的关键字,因为为什么不投票?这是一个合理的问题。