Share Content with Flutter Share Plugin
By Philomathes in Flutter
Are you creating a Flutter application that has content users may want to share with their friends or coworkers? Take advantage of the native platform share dialog using the share plugin. Let’s see how it’s done.
Adding the Share plugin
Head over to your pubspec.yaml and add the following plugin:
dependencies:
flutter:
sdk: flutter
share: any
Add the following imports to your Dart code:
import ‘package:share/share.dart’;
Adding the Share functionality
In order to make it so that whenever the user clicks on a widget, we’ll hook into the onTap functionality, calling a share function:
String text = ‘https://www.vayuz.co’;
String subject = ‘follow me’;
In this package you can add only two texts or String but you can configure it. Take any clickable widget, you can take reference Deep Dive Into Buttons & Clickable Widgets In Flutter.
RaisedButton(
child: Text(‘Share’),
onPressed: ()
{
final RenderBox box = context.findRenderObject();
Share.share(text,
subject: subject,
sharePositionOrigin:
box.localToGlobal(Offset.zero) &
box.size);
},
);
And you are done. You have successfully implemented the share functionality in Flutter
Leave a Comment
You must be logged in to post a comment.