How to implement a share button in Flutter app?

42,792

Solution 1

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

Solution 2

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.

Solution 3

This is for us Flutter noobs, a more complete solution.

  1. Add this at the top of your .dart file:

    
    import 'package:share/share.dart';
    
    
  2. Run this command in your Terminal:

    
    flutter pub add share
    
    
  3. 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:

https://pub.dartlang.org/packages/share

Solution 4

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.

Solution 5

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.

Share:
42,792

Related videos on Youtube

asls2
Author by

asls2

Updated on October 15, 2021

Comments

  • asls2
    asls2 over 2 years

    In my app, I have a button and I need it to share Facebook when this button is clicked?

    • Dhrumil Shah - dhuma1981
      Dhrumil Shah - dhuma1981 about 6 years
      You want to share on Facebook? or Just want share ?
    • asls2
      asls2 about 6 years
      on facebook @dhuma1981
  • Jamie White
    Jamie White over 5 years
    Does it now support ios? Do you have example of how to post to fb timeline?
  • Jamie White
    Jamie White over 5 years
    Do you have example of how to post to fb timeline?
  • Tree
    Tree over 5 years
    you need to have installed facebook on your phone, than facebook will be in the options to choose from once you click share
  • Rony Tesler
    Rony Tesler almost 4 years
    What about a plugin that supports flutter web?
  • HaKim
    HaKim over 2 years
    Does anyone know why this plugin does not share text on facebook and fb msger?!
  • Sachin Chillal
    Sachin Chillal over 2 years
    Don't know exactly, but the reason may be privacy policy, limitations, and security at different platforms.