首页 > 解决方案 > 如何分享从颤振下载的图像

问题描述

我使用颤振将小部件保存为颤振中的图像。我下载图像没有问题,但我在分享图像时遇到了麻烦。有没有办法在不离开应用程序的情况下共享下载的图像?

这是我现在的代码

   onPressed: () async {
    if (await Permission.storage.request().isGranted) {
      screenshotController.capture(pixelRatio: 1.5);
      screenshotController.capture().then((File image) async {
        await ImageGallerySaver.saveImage(image.readAsBytesSync());

        Navigator.of(context, rootNavigator: true).pop();
        Scaffold.of(context).showSnackBar(
          SnackBar(
            content: Text("Image Saved to Gallery"),
            duration: const Duration(seconds: 1),
          ),
        );
      }).catchError((onError) {
//                                    print(onError);
      });
    } else {
      await Permission.storage.request();
    }
  }

标签: androidiosxcodeandroid-studioflutter

解决方案


您需要像处理任何其他文件一样处理图像。

如果您不打算在两个用户之间使用服务器,这有点棘手,因为其中一个必须充当一个,但如果您将使用服务器,我建议您关注这篇文章:

https://dev.to/carminezacc/advanced-flutter-networking-part-1-uploading-a-file-to-a-rest-api-from-flutter-using-a-multi-part-form-data-请求后 2ekm

它是最新的,可以帮助您编写应用程序代码,甚至是用 nodejs 编写的服务器示例。这篇文章的下一部分教你做你想做的事。


推荐阅读