gpt4 book ai didi

dart - 在flutter中分享图片+文字+网址的便捷方式

转载 作者:行者123 更新时间:2023-12-04 21:03:02 26 4
gpt4 key购买 nike

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

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

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

最佳答案

Simple Share 似乎正是您要找的:

    import 'package:flutter/material.dart';
import 'package:file_picker/file_picker.dart';
import 'package:simple_share/simple_share.dart';
import 'package:flutter/services.dart';

void main() => runApp(SimpleShareApp());

class SimpleShareApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
showPerformanceOverlay: false,
title: 'Simple Share App',
home: MyHomePage()
);
}
}

class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
Future<String> getFilePath() async {
try {
String filePath = await FilePicker.getFilePath(type: FileType.ANY);
if (filePath == '') {
return "";
}
print("File path: " + filePath);
return filePath;
} on PlatformException catch (e) {
print("Error while picking the file: " + e.toString());
return null;
}
}

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('File Picker Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
onPressed: () {
SimpleShare.share(
title: "Share my message",
msg:
"Lorem ipsum dolor sit amet, consectetur adipisci elit, sed eiusmod " +
"tempor incidunt ut labore et dolore magna aliqua.",
);
},
child: Text('Share text!'),
),
RaisedButton(
onPressed: () async {
final path = await getFilePath();
if (path != null && path.isNotEmpty) {
final uri = Uri.file(path);
SimpleShare.share(
uri: uri.toString(),
title: "Share my file",
msg: "My message");
}
},
child: Text('Share file!'),
),
],
),
),
);
}
}

Source

关于dart - 在flutter中分享图片+文字+网址的便捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54453247/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com