【发布时间】:2018-05-28 22:09:32
【问题描述】:
在我的应用程序中,我有一个按钮,我需要在单击此按钮时分享 Facebook?
【问题讨论】:
-
您想在 Facebook 上分享?还是只想分享?
-
在脸书上@dhuma1981
在我的应用程序中,我有一个按钮,我需要在单击此按钮时分享 Facebook?
【问题讨论】:
查看 Flutter 分享插件
https://pub.dartlang.org/packages/share
Share.share('check out my website https://example.com');
比使用可以选择使用facebook或任何其他支持分享界面的服务
【讨论】:
你可以试试这个包: https://pub.dev/packages/wc_flutter_share
此包支持图片+文字共享。
你可以这样使用:
await WcFlutterShare.share(
sharePopupTitle: 'share',
subject: 'This is subject',
text: 'This is text',
fileName: 'share.png',
mimeType: 'image/png',
bytesOfFile: bytes.buffer.asUint8List());
注意: 在 facebook 上您不能同时分享图片和文字。您可以分享文字或图片。
【讨论】:
试试这个:https://github.com/d-silveira/flutter-share.git
如果您想分享文本以外的内容。
它允许使用简单的命名构造函数实例化Share.image(path: <PATH>, title: <TITLE>) 共享文本/图像/文件,然后在其上调用share()
只需按照说明了解有关 README 的更多详细信息,或查看示例项目文件夹中的工作示例。
它完全适用于Android,目前正在开发IOS部分以匹配Android部分。
【讨论】:
这是为我们 Flutter 菜鸟准备的,一个更完整的解决方案。
在 .dart 文件的顶部添加:
import 'package:share/share.dart';
在终端中运行此命令:
flutter pub add share
将分享代码添加到onPressed中的按钮代码中:
onPressed: () {
Share.share('check out my website https://example.com', subject: 'Look what I made!');
}),
有关共享包的更多信息可以在下面的链接中找到:
【讨论】:
share_plus 3.0.4:https://pub.dev/packages/share_plus 一个 Flutter 插件,用于通过平台的共享对话框共享来自 Flutter 应用的内容。
使用 Flutter 运行此命令:
$ flutter pub add share_plus
这将在你的包的 pubspec.yaml 中添加这样的一行(并运行隐式颤振 pub get):
dependencies:
share_plus: ^3.0.4
import 'package:share_plus/share_plus.dart';
Share.share('hey! check out this new app https://play.google.com/store/search?q=pub%3ADivTag&c=apps');
Share.share('hey! check out this new app https://play.google.com/store/search?q=pub%3ADivTag&c=apps', subject: 'DivTag Apps Link');
Platform Support : 安卓 | iOS | macOS |网站 | Linux |窗户
share 2.0.4 : https://pub.dev/packages/share 这个插件已经被 Flutter Community Plus Plugins 版本替换为 share_plus。没有计划对此插件进行进一步更新,它们鼓励所有用户迁移到 Plus 版本。
【讨论】: