This is the 13th day of my participation in the August More text Challenge. For details, see: August More Text Challenge
I wrote this plug-in because I needed to share it with some apps. At the beginning, I only supported Android version. Recently, I added ios support and released the latest version after testing.
flutter_share_me
The Flutter plugin for sharing content on social media. Support for Android & iOS
You can use it to share to Facebook, WhatsApp(WhatsAppBusiness), Twitter and system share. Supports urls and text, and whatsapp supports pictures
Note: This plug-in is still under development and some apis may not be available yet. Feedback and pull requests are very welcome!
start
add flutter_share_me
as a dependency in your pubspec.yaml file.
Please check the latest version
Add flutter_share_me: ^1.0.0Copy the code
Set up the
Android
Add “Facebook App ID” to the application tag to AndroidManifest.xml
<application> ... //add this <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" /> <provider android:name="com.facebook.FacebookContentProvider" android:authorities="com.facebook.app.FacebookContentProvider[facebook_app_id]" android:exported="false" /> </application>Copy the code
string.xml:
<? The XML version = "1.0" encoding = "utf-8"? > <resources> <! -- Replace "343254889799245" with your Facebook App ID here. --> <string name="facebook_app_id">343254889799245</string> </resources>Copy the code
IOS
setup facebook
Be sure to add the following details to your PList file.
<key>FacebookAppID</key>
<string>fbid</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb-your-fb-id</string>
</array>
</dict>
</array>
Copy the code
Note: Make sure fb is added at the beginning of fb Id in CFBundleURLSchemes. Add the following values to the URL schema.
<array>
<string>fbauth2</string>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbapi20160328</string>
<string>fbauth</string>
<string>fb-messenger-share-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
Copy the code
Set the Whatsapp
Make sure you add whatsapp in plist.
<array>
<string>whatsapp</string>
</array>
Copy the code
Set the Twiter
<array>
<string>twitter</string>
</array>
Copy the code
use
Add the following import to your Dart code:
import 'package:flutter_share_me/flutter_share_me.dart';
Copy the code
methods
shareToFacebook({String msg, String url})
shareToTwitter({String msg, String url})
shareToWhatsApp({String msg,String imagePath})
shareToWhatsApp4Biz({String msg,String imagePath})
shareToSystem({String msg}) use system share ui
These methods will return “SUCCESS” if they successfully jump to the corresponding application.
Parameter | Description |
---|---|
String msg | Shared text |
String url | Shared links |
String imagePath | Image path |
Example
Container(
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(height: 30),
ElevatedButton(
onPressed: () => onButtonTap(Share.twitter),
child: Text('share to twitter')),
ElevatedButton(
onPressed: () => onButtonTap(Share.whatsapp),
child: Text('share to WhatsApp'),
),
ElevatedButton(
onPressed: () => onButtonTap(Share.whatsapp_business),
child: Text('share to WhatsApp Business'),
),
ElevatedButton(
onPressed: () => onButtonTap(Share.facebook),
child: Text('share to FaceBook'),
),
ElevatedButton(
onPressed: () => onButtonTap(Share.share_system),
child: Text('share to System'),
),
],
),
)
Copy the code