Reputation: 4565
I just want to share my app link to social media like facebook, twitter, Instagram but currently just wanna share simple text on social media.
here, what I have tried:
I used social_share_plugin
package but getting an Exception on compile time.
code for facebook
IconButton(
icon:Image.asset("assets/icons/facebook_logo1.png",fit:BoxFit.contain,color: Colors.white,),
onPressed: ()async{
String faceString="Sharing My App";
await SocialSharePlugin.shareToFeedFacebook('caption', faceString);
},
),
for instagram
IconButton(
icon:Image.asset("assets/icons/instagram_logo1.png",fit:BoxFit.contain,color: Colors.white,),
onPressed: ()async{
String instaString="Sharing My App";
await SocialSharePlugin.shareToFeedInstagram('caption', instaString);
},
)
Upvotes: 1
Views: 7568
Reputation: 1022
You can use this plugin https://pub.dev/packages/flutter_social_content_share
/// SHARE ON FACEBOOK CALL
shareOnFacebook() async {
String result = await FlutterSocialContentShare.share(
type: ShareType.facebookWithoutImage,
url: "https://www.apple.com",
quote: "captions");
print(result);
}
/// SHARE ON INSTAGRAM CALL
shareOnInstagram() async {
String result = await FlutterSocialContentShare.share(
type: ShareType.instagramWithImageUrl,
imageUrl:
"https://post.healthline.com/wp-content/uploads/2020/09/healthy-eating-ingredients-732x549-thumbnail-732x549.jpg");
print(result);
}
/// SHARE ON WHATSAPP CALL
shareWatsapp() async {
String result = await FlutterSocialContentShare.shareOnWhatsapp(
number: "xxxxxx", text: "Text appears here");
print(result);
}
/// SHARE ON EMAIL CALL
shareEmail() async {
String result = await FlutterSocialContentShare.shareOnEmail(
recipients: ["[email protected]"],
subject: "Subject appears here",
body: "Body appears here",
isHTML: true); //default isHTML: False
print(result);
}
/// SHARE ON SMS CALL
shareSMS() async {
String result = await FlutterSocialContentShare.shareOnSMS(
recipients: ["xxxxxx"], text: "Text appears here");
print(result);
}
///Build Context
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: <Widget>[
Text('Running on: $_platformVersion\n'),
RaisedButton(
child: Text("Share to facebook button"),
color: Colors.red,
onPressed: () {
shareOnFacebook();
},
),
RaisedButton(
child: Text("Share to instagram button"),
color: Colors.red,
onPressed: () {
shareOnInstagram();
},
),
RaisedButton(
child: Text("Share to whatsapp button"),
color: Colors.red,
onPressed: () {
shareWatsapp();
},
),
RaisedButton(
child: Text("Share to email button"),
color: Colors.red,
onPressed: () {
shareEmail();
},
),
RaisedButton(
child: Text("Share to sms button"),
color: Colors.red,
onPressed: () {
shareSMS();
},
),
],
),
),
);
}
Upvotes: 1
Reputation: 8264
you can use the share plugin
and then here is how you share your data
import 'package:share/share.dart';
IconButton(
icon:Image.asset("assets/icons/facebook_logo1.png",fit:BoxFit.contain,color: Colors.white,),
onPressed: (){
Share.share('check out my website https://example.com');
}
`),
Upvotes: 0