twitter_login 2.0.0
twitter_login: ^2.0.0 copied to clipboard
Flutter Twitter Login Plugin. Library for login with Twitter APIs OAuth service
twitter_login #
Flutter Twitter Login Plugin
Requirements #
- Dart sdk: ">=2.7.0 <3.0.0"
- Flutter: ">=1.10.0"
- Android: minSdkVersion 17 and add support for androidx
- iOS: --ios-language swift, Xcode version >= 11
Android Configuration #
Add intent filters for incoming links #
/example/android/app/src/main/AndroidManifest.xm
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "example://gizmos” -->
<data android:scheme="example"
android:host="gizmos" />
</intent-filter>
Supporting the new Android plugins APIs #
If you flutter created your project prior to version 1.12, you need to make sure to update your project in order to use the new Java Embedding API. Make use you have flutter_embedding v2 enabled. Add the following code on the manifest file inside
<meta-data
android:name="flutterEmbedding"
android:value="2" />
iOS Configuration #
Add URLScheme #
/example/ios/Runner/Info.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>app.flutter.twitter.login.schemes</string>
<key>CFBundleURLSchemes</key>
<array>
<string>app</string>
</array>
</dict>
</array>
Example code #
See the example directory for a complete sample app using twitter_login.
Usage #
To use this plugin, add twitter_login
as a dependency in your pubspec.yaml file.
Example #
import 'package:flutter/material.dart';
import 'package:twitter_login/twitter_login.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: FlatButton(
child: Text('login'),
onPressed: () async {
final twitterLogin = TwitterLogin(
// Consumer API keys
apiKey: 'xxxx',
apiSecretKey: 'xxxx',
// Callback URL for Twitter App
// Android is a deeplink
// iOS is a URLScheme
redirectURI: 'URLScheme',
);
// If you want to implement Twitter account switching, set [force_login] to true
// login(forceLogin: true);
final authResult = twitterLogin.login();
switch (authResult.status) {
case TwitterLoginStatus.loggedIn:
// success
break;
case TwitterLoginStatus.cancelledByUser:
// cancel
break;
case TwitterLoginStatus.error:
// error
break;
}
},
),
),
),
);
}
}