Create Share Button in Flutter

Create Share button in Flutter

Flutter plugin to Sharing Text, Link, content, etc from Flutter App through the platform’s share dialog. To Add ACTION_SEND for Android and UIActivityViewController for iOS.

Install the package

After creating a new flutter document move to pubspec.yaml file

Find Dependencies and then add the package name.

Dependencies:

share : ^0.5.3

Note: you should add under cupertino_icons: ^0.1.2

Install the package

Tap Package gets at right corner.

Note: It is only available for Android.

Import the Package

Import the package under the basic package

import 'package:share/share.dart';

How to Add a Text Field

             

new TextField(
                  decoration: const InputDecoration(
                    labelText: 'Share:',
                    hintText: 'Enter your Text',
                  ),
             

maxLines: 2,
                  onChanged: (String value) => setState(() {
                    text = value;
                  }),
                ),

How to Add a Text FieldHow to Set the Share Page

              

const Padding(padding: EdgeInsets.only(top: 24.0)),
                new Builder(
                  builder: (BuildContext context) {
                    return new RaisedButton(
                      child: const Text('Share'),
                      onPressed: text.isEmpty
                          ? null
                          : () {
                        final RenderBox box = context.findRenderObject();
                        Share.share(text,
                            sharePositionOrigin:
                            box.localToGlobal(Offset.zero) &
                            box.size);
                      },
                    );
                  },
                ),

            

How to Set the Share PageNote: If you get the “timeout waiting for the application to start error in flutter move to pubspec.yaml> Packages upgrade.