在flutter中分享图片+文字+网址的便捷方式 [英] Convenient way to share image + text + url in flutter

查看:373
本文介绍了在flutter中分享图片+文字+网址的便捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道从 flutter 应用程序共享的官方包.https://pub.dartlang.org/packages/share

I know official package to sharing from flutter app. https://pub.dartlang.org/packages/share

共享文本和 url 很容易,但我想共享来自服务器的图像意味着它是 URL 格式,所以可能首先我必须将 url 转换为图像,然后我必须将图像转换为 base64 然后我想我可以分享图片但我正在寻找一种简单的方式来分享图片+文字+网站.

Its easy to share text and url but I want to share image that is coming from server means its in URL format so may be first I have to convert url to image and then I have to convert image to base64 then I think I can share image But I'm looking for easy way to share image+text+website.

官方分享包怎么办?任何其他维护良好的软件包?

How can I do by official share package? Any other package that maintained well?

推荐答案

官方分享包添加在 v0.6.5 中支持共享文件,因此现在您可以将图像保存到文件并共享该文件.请参阅下面的示例,其中包含从 Internet 下载的图像:

The official share package added support for sharing files in v0.6.5, so now you can save the image to a file and share that file. See below an example with an image downloaded from Internet:

import 'package:http/http.dart';
import 'package:share/share.dart';
import 'package:path_provider/path_provider.dart';

void shareImage() async {
    final response = await get(imageUrl);
    final bytes = response.bodyBytes;
    final Directory temp = await getTemporaryDirectory();
    final File imageFile = File('${temp.path}/tempImage');
    imageFile.writeAsBytesSync(response.bodyBytes);
    Share.shareFiles(['${temp.path}/tempImage'], text: 'text to share',);
}

这篇关于在flutter中分享图片+文字+网址的便捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆