它们两者有什么不同吗?
什么是劣势,哪一个更容易在正常情况下使用?
解决方法
Are there any difference in both of them?
是.它们是不同的.
> NetworkImage类创建一个对象,该对象提供传递给它的src URL中的图像.它不是小部件,不会将图像输出到屏幕.
> Image.network创建一个在屏幕上显示图像的小部件.它只是Image类(有状态小部件)上的命名构造函数.它使用NetworkImage设置image属性.最终使用此图像属性来显示图像.
class Image extends StatefulWidget{ Image(...){}; //default Constructor //the argument src is passed to the NetworkImage and assinged to the image property Image.network(String src,{...}) : image = NetworkImage(src,...); final ImageProvider image; @override Widget build(BuildContext context){ display the image return RawImage(image: image,... ); } }
Whats the disadvantage and which one is easier to use for normal situation?
没有缺点.你应该使用适合自己需要的那个.例如考虑:
> CircleAvatar显示代表用户的acircle的小部件采用backgroundImage.它需要一个ImageProvider.所以你通过NetworkImage(http://image.com)
> FadeInImage在原始图像加载时显示占位符还会为其图像属性采用ImageProvider.所以你可以提供它NetworkImage(http://image.com).
如果您只想在屏幕上将图像显示为小部件,请使用Image.network并在需要ImageProvider的任何地方使用NetworkImage.