简体   繁体   English

在 Flutter - 如何传递从 url 下载的图像

[英]In Flutter - How to pass the image downloaded from the url

Through the API I retrieve data of an object - including its url.通过 API 我检索了 object 的数据——包括它的 url。 I show on one screen an image with url (Image.Network()).我在一个屏幕上显示带有 url (Image.Network()) 的图像。 Now, after clicking on this image on the list, I want to move to a single image view - how do I pass the image, not the url, to a new view so that the application doesn't have to download it from the url again?现在,单击列表上的此图像后,我想移动到单个图像视图 - 如何将图像而不是 url 传递到新视图,以便应用程序不必从 url 下载它再次?

you can pass the image to Other Class like this您可以像这样将图像传递给其他 Class

Navigator.push(
          context, MaterialPageRoute(builder: (context) => OtherClass(data: image)));

and in Other class receive the image like并在其他 class接收图像

   var data;

   OtherClass({Key key, @required this.data}) : super(key: key);

My code:我的代码:

onTap: () {
            Navigator.push(context, MaterialPageRoute(builder: (_) {
            return DetailScreen(url: users[index].url);
        }));
    },
[...]
class DetailScreen extends StatelessWidget {
    final String url;

    DetailScreen({Key key, @required this.url})
        : assert(url != null),
            super(key: key);
    @override
    Widget build(BuildContext context) {
        return Scaffold(
            body: GestureDetector(
                child: Center(
                    child: PhotoView(
                        imageProvider: NetworkImage(url),
                    )
                ),
                onTap: () {
                    Navigator.pop(context);
                },
            ),
        );
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何分享从flutter下载的图片 - How to share image downloaded from flutter 如何将下载的图像从一个活动传递到下一个活动? - How do I pass a downloaded image from one activity to the next? 从网址下载的图片未显示在视图中 - downloaded image from url is not showing in view 如何保持从 url 下载到 imageview 的图像质量并将它们裁剪成圆形? - How to maintain quality of the image downloaded from url to imageview and crop them to a circle? 为什么我的图片无法从android中的URL下载? - Why is my Image not getting downloaded from the URL in android? 如何访问从网络下载的图像 - How to access image downloaded from the web (Android应用)尝试将AlertDialog .setIcon()设置为从URL下载的图像 - (Android App) Trying to set AlertDialog .setIcon() as an image downloaded from URL Android - 将下载的图像从 URL 保存到 SD 卡上 - Android - Saving a downloaded image from URL onto SD card 如何从Android的内存中释放下载的图像? - How to free downloaded image from memory in android? 如何首先从NetworkImageView中的URL显示缩略图图像并在后台请求大尺寸图像并在下载大图像时显示? - How to first show thumb image from URL in NetworkImageView and request a large size image in background and show when large one downloaded?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM