加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

dart – NetworkImage和Image.network的区别?

发布时间:2020-12-14 14:52:56 所属栏目:百科 来源:网络整理
导读:它们两者有什么不同吗? 什么是劣势,哪一个更容易在正常情况下使用? 解决方法 Are there any difference in both of them? 是.它们是不同的. NetworkImage类创建一个对象,该对象提供传递给它的src URL中的图像.它不是小部件,不会将图像输出到屏幕. Image.ne
它们两者有什么不同吗?

什么是劣势,哪一个更容易在正常情况下使用?

解决方法

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读