【问题标题】:In Flutter show image form gallery or from network in same view在 Flutter 中显示图像表单库或来自网络的同一视图
【发布时间】:2019-12-26 06:05:56
【问题描述】:

我正在从图库中选择图像,然后将其上传到服务器上,然后在成功上传后,我将使用一个 API 从服务器检索相同的图像,并希望在我使用的同一 ImageView 中显示该图像 Image。文件 加载点击的图像和 Image.network 显示网络图像,但我想要一件事来加载图像

【问题讨论】:

  • 请给我看你的代码
  • 只需设置一个布尔值 isImageUploaded,如果为真则显示 Image.network 小部件,否则为 Image.asset 图片
  • 我需要一个函数来加载图像,有没有这个库?
  • 在 android studio 中我们有 picasso 和 Glide,就像 Flutter 中的同一个库?
  • 试试cachedImageNetwork,当url失败时可以从文件中设置

标签: flutter networkimageview image-file


【解决方案1】:

试试这个,只需设置一个布尔值 isProfileImageIsURL,如果为 true,则显示 NetworkImage 小部件,否则为 FileImage

isProfileImageIsURL ? NetworkImage(profileImageURL) : FileImage(_profilePictureFile);

【讨论】:

  • 这就是我在上面对您的评论的回复,我使用的是相同的条件,但我需要单个图像加载器来完成这两个操作
  • else 从 url 加载图片并隐藏文件,然后在 FileImage 中使用。
  • 感谢您的回复,因为我只在我的代码中使用三元运算符。
猜你喜欢
  • 1970-01-01
  • 2019-08-12
  • 2011-04-27
  • 1970-01-01
  • 2020-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-04
相关资源
最近更新 更多