简体   繁体   English

如何在flutter中从app + web中的URL下载图像?

[英]How to download image from URL in app + web in flutter?

是否有任何软件包或方法可用于从网页和应用程序中的颤振中的 URL 保存/下载图像。

You can use Firebase storage or s3-Cognito to achieve this.您可以使用 Firebase 存储或 s3-Cognito 来实现这一点。 First, you need to upload the image to the Database using file picker or image picker and use the getDownloadUrl() method to get the imageUrl首先,您需要使用文件选择器或图像选择器将图像上传到数据库,并使用 getDownloadUrl() 方法获取 imageUrl

You don't need a package.你不需要一个包。



import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'dart:typed_data';

TextButton(
        onPressed: () async {
          String imageUrl='https://......example';
          Uint8List response = await http.get(Uri.parse(imageUrl)).then(
          (value) => value.bodyBytes);
          
          showDialog(
            context: context,
            builder: (BuildContext context) {
              return AlertDialog(
              content: Image.memory(response),
              );
            },
          );
        },
        child: Text(
          'Show Image from memory',
        ));

This code alone works without any packages.此代码单独工作,无需任何包。 Now that you have it in memory, you can store it and do other things with it.既然您已将其保存在内存中,就可以存储它并用它做其他事情。 Convert it between base64 and Unit8List.在 base64 和 Unit8List 之间进行转换。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM