flutter_facebook_login_web 0.2.1+1 flutter_facebook_login_web: ^0.2.1+1 copied to clipboard
A Flutter plugin for using the native Facebook Login SDKs on Web.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter_facebook_login_web/flutter_facebook_login_web.dart';
//import 'package:flutter_facebook_login/flutter_facebook_login.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _message = '';
static final facebookSignIn = FacebookLoginWeb();
Future<Null> _login() async {
final FacebookLoginResult result = await facebookSignIn.logIn(['email']);
switch (result.status) {
case FacebookLoginStatus.loggedIn:
final FacebookAccessToken accessToken = result.accessToken;
_showMessage('''
Logged in!
Token: ${accessToken.token}
User id: ${accessToken.userId}
''');
facebookSignIn.testApi();
break;
case FacebookLoginStatus.cancelledByUser:
_showMessage('Login cancelled by the user.');
break;
case FacebookLoginStatus.error:
_showMessage('Something went wrong with the login process.\n'
'Here\'s the error Facebook gave us: ${result.errorMessage}');
break;
}
}
Future<Null> _logOut() async {
await facebookSignIn.logOut();
_showMessage('Logged out.');
}
void _showMessage(String message) {
setState(() {
_message = message;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: <Widget>[
Text(_message),
RaisedButton(
onPressed: _login,
child: Text("Login with Facebook"),
),
RaisedButton(
onPressed: _logOut,
child: Text("Logout"),
),
],
),
),
),
);
}
}