In my app, I have a button and I need it to share Facebook when this button is clicked?
Check out flutter share plugin
https://pub.dev/packages/share_plus
Share.share('check out my website https://example.com');
Then users can choose to use facebook or any other service that supports share interface
You can try this package: https://pub.dev/packages/wc_flutter_share
This package supports sharing image + text both.
You can use this like:
await WcFlutterShare.share(
sharePopupTitle: 'share',
subject: 'This is subject',
text: 'This is text',
fileName: 'share.png',
mimeType: 'image/png',
bytesOfFile: bytes.buffer.asUint8List());
Note: On facebook you can't share image and text at the same time. You can either share text or image.
This is for us Flutter noobs, a more complete solution.
Add this at the top of your .dart file:
import 'package:share/share.dart';
Run this command in your Terminal:
flutter pub add share
Add the share code into the button code in onPressed:
onPressed: () { Share.share('check out my website https://example.com', subject: 'Look what I made!'); }),
More information about the share package can be found on the link below:
try this: https://github.com/d-silveira/flutter-share.git
if you want to share something other than text.
it allows sharing text/image/file with a simple named constructor instantiation Share.image(path: <PATH>, title: <TITLE>)
and then call share()
on it
just follow the instructions for further details on the README or see a working example in the example project folder.
It is fully functional for Android, the IOS part is currently being developed to match the Android part.
share_plus 3.0.4: https://pub.dev/packages/share_plus A Flutter plugin to share content from your Flutter app via the platform's share dialog.
Run this command with Flutter:
$ flutter pub add share_plus
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):
dependencies:
share_plus: ^3.0.4
- Import the library
import 'package:share_plus/share_plus.dart';
- Then invoke the static share method anywhere in your Dart code.
Share.share('hey! check out this new app https://play.google.com/store/search?q=pub%3ADivTag&c=apps');
- The share method also takes an optional subject that will be used when sharing to email.
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 : Android | iOS | MacOS | Web | Linux | Windows
Note
share 2.0.4 : https://pub.dev/packages/share This plugin has been replaced by the Flutter Community Plus Plugins version, to share_plus. No further updates are planned to this plugin, and they are encourage all users to migrate to the Plus version.
You can try this package:
https://pub.dev/packages/share_plus
Share.shareXFiles([XFile(file.path)], text: 'filename');
© 2022 - 2024 — McMap. All rights reserved.