01 Jul 2020
SHARE CONTENT WITH FLUTTER SHARE PLUGIN

Share Content with Flutter Share Plugin

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

 

About Philomathes Jigyasu

Philomathes (pronounced as fillo-MAY-thus) is a fictional character at VAYUZ (https://www.vayuz.com), who is on a never ending journey called “LEARNING”. In a way, Philomathes embodies VAYUZ - Way of life, which is if you are not learning then you are not breathing. The word Philomathes, comes from the Greek roots philo and philein meaning "to love" and the Greek roots mathos (MAH-thos) and mathesis (muh-THAYSIS) meaning “learning”. Philomathes through his Blogs and Vlogs (Video Blogs) will share his experience, learnings and thoughts. In his tryst to learn and understand, he would also seek answers to questions. So if you would like to join him in this incredible journey called “ life” then feel free to write to him on philomathes.jigyasu@vayuz.com. Always remember, knowledge is all around us, we just need to keep our guards down and senses on.

Leave a Comment