share_social_media_plugin 1.3.7 share_social_media_plugin: ^1.3.7 copied to clipboard
Share social media plugin, share Line, Twitter, FB, Instagram and more!, I try develop step for step. Any suggestion please contact me.
Share social media plugin
Getting Started #
This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.
For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.
Share text in your social media.
- Line (Android / iOS) π
- Twitter (Android / iOS) π
- Instagram (Android /iOS) π
Example #
Share in Line.
await ShareSocialMediaPlugin.shareLine("My share text");
Share in Twitter
//Set keys
final twitterLogin = new ShareSocialMediaPlugin(
consumerKey: "consumerKey",
consumerSecret: 'consumerSecret');
RaisedButton(
child: Text('Share in Twitter', style: TextStyle(fontSize: 20)),
onPressed: () async {
if (Platform.isAndroid) {
twitterLogin.isSessionActive.then((isConnected) async{
if (!isConnected){
twitterLogin.connectTwitter();
}
else{
var response =
await twitterLogin.shareTwitter("example test in android");
if (response['text'] != null) {
//Success
} else {
//Fail
}
}
});
} else if (Platform.isIOS) {
if (outhTokenTwitter != null) {
var tweet = await twitterLogin.shareTwitteriOS(
outhTokenTwitter,
oauthTokenSecretTwitter,
"test6",
twitterLogin.consumerKey,
twitterLogin.consumerSecret);
final response = json.decode(tweet.body);
if (response['text'] != null) {
//Success
print(tweet.body);
} else {
//Fail
print(tweet.body);
}
} else {
//Connect twitter
var sessionTwitter = await twitterLogin.currentSessionIOS();
outhTokenTwitter = sessionTwitter["outhToken"];
oauthTokenSecretTwitter =
sessionTwitter["oauthTokenSecret"];
}
}
},
),
**Note For iOS Twitter In plist add:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>TwitterLoginSampleOAuth</string>
</array>
</dict>
</array>
Add in your Delegate
ios/Runner/AppDelegate.swift
import OAuthSwift
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
//Add this
override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if (url.host == "oauth-callback") {
OAuthSwift.handle(url: url)
}else{
OAuthSwift.handle(url: url)
}
return true
}
}
!IMPORTANT
In your developer.twitter.com app , you need add the next callback
-TwitterLoginSampleOAuth://
-twittersdk://
Instagram- Share stories (ios /android) #
##Android Read some image from flutter assets
RaisedButton(
onPressed: () async {
await ShareSocialMediaPlugin.shareInstagram("hello","assets/nofumar.jpg");
},
child: Text('Share in Instagram', style: TextStyle(fontSize: 20)),
)
Public image from album phone
RaisedButton(
onPressed: () async {
await ShareSocialMediaPlugin.shareInstagramAlbum();
},
child: Text('Share in Instagram from album', style: TextStyle(fontSize: 20)),
)
(For any case add this code in your AndroidManifest.xml)
android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
iOS #
π₯
RaisedButton(
onPressed: () async {
//shareInstagram("message","image","background");
await ShareSocialMediaPlugin.shareInstagram("hello","assets/my_image.jpg","assets/background");
},
child: Text('Share in Instagram', style: TextStyle(fontSize: 20)),
)
In your plist add
<key>LSApplicationQueriesSchemes</key>
<array>
<string>instagram-stories</string>
</array>
**The user needs to have instagram installed
Thank you!! πΊπΊπΊπΊπΊπΊ
Thank you for your repo https://github.com/bodnarrr/flutter_twitter_login/blob/master/android/src/main/java/com/bodnarrr/fluttertwitterlogin/fluttertwitterlogin/TwitterLoginPlugin.java