flutter_twitter 1.1.2 flutter_twitter: ^1.1.2 copied to clipboard
A Flutter plugin for allowing users to authenticate with native Android & iOS Twitter login SDKs.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_twitter/flutter_twitter.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
static final TwitterLogin twitterLogin = new TwitterLogin(
consumerKey: 'YOURCONSUMERKEY',
consumerSecret: 'YOURSECRET',
);
String _message = 'Logged out.';
void _login() async {
final TwitterLoginResult result = await twitterLogin.authorize();
String newMessage;
switch (result.status) {
case TwitterLoginStatus.loggedIn:
newMessage = 'Logged in! username: ${result.session.username}';
break;
case TwitterLoginStatus.cancelledByUser:
newMessage = 'Login cancelled by user.';
break;
case TwitterLoginStatus.error:
newMessage = 'Login error: ${result.errorMessage}';
break;
}
setState(() {
_message = newMessage;
});
}
void _logout() async {
await twitterLogin.logOut();
setState(() {
_message = 'Logged out.';
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Twitter login sample'),
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(_message),
new RaisedButton(
child: new Text('Log in'),
onPressed: _login,
),
new RaisedButton(
child: new Text('Log out'),
onPressed: _logout,
),
],
),
),
),
);
}
}