“图像"和“图像"有什么区别?和“图像提供者"在颤振? [英] What is the difference between an "Image" and "ImageProvider" in Flutter?

查看:8
本文介绍了“图像"和“图像"有什么区别?和“图像提供者"在颤振?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有与此主题相关的答案,但它们提供的是解决方法而不是解释.

There are answers related to this topic but they offer workarounds rather than explanations.

为什么不能在需要 ImageProvider 的地方使用 Image?从概念上讲,它们对我来说听起来是一样的.

Why can't an Image be used where an ImageProvider is required? Conceptually they sound the same to me.

child: new CircleAvatar(
  backgroundImage: NetworkImage("https..."),        // works
  backgroundImage: Image.asset('images/image.png'), // error
),

尝试直接使用图片产生的错误是:

The error generated by trying to use an image directly is:

错误:无法将参数类型Image"分配给参数类型ImageProvider".

error: The argument type 'Image' can't be assigned to the parameter type 'ImageProvider'.

推荐答案

Image 是一个显示图像的小部件.

An Image is a widget that displays an image.

ImageProvider 允许您在不知道最终资产的确切位置的情况下识别图像.稍后当有人想要读取图像时,将解析资产的位置.

The ImageProvider instead allows you to identify an image without knowing exactly where is the final asset. The place of the asset will be resolved later when someone wants to read the image.

这篇关于“图像"和“图像"有什么区别?和“图像提供者"在颤振?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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