lecle_flutter_facebook_login 0.0.1 lecle_flutter_facebook_login: ^0.0.1 copied to clipboard
A Flutter plugin for using the native Facebook Login SDKs on Android and iOS.
import 'dart:io';
import 'package:flutter/material.dart';
// import 'package:lecle_flutter_facebook_login/enums/enums.dart';
import 'package:lecle_flutter_facebook_login/lecle_flutter_facebook_login.dart';
import 'package:permission_handler/permission_handler.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _facebookSignIn = LecleFlutterFacebookLogin();
@override
void initState() {
super.initState();
if (Platform.isIOS) {
Permission.appTrackingTransparency.request();
}
// _facebookSignIn.setLoginBehavior(FacebookLoginBehavior.webOnly);
// _facebookSignIn.loginBehavior = FacebookLoginBehavior.webOnly;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton(
onPressed: () {
_facebookSignIn.logIn().then((result) {
print('Facebook login status ::: ${result?.status}');
print(
'Facebook login token ::: ${result?.accessToken?.toJson()}');
});
},
child: const Text('Login'),
),
Visibility(
visible: Platform.isAndroid,
child: ElevatedButton(
onPressed: () {
_facebookSignIn.expressLogin().then((result) {
print(
'Facebook express login status ::: ${result?.status}');
print(
'Facebook express login token ::: ${result?.accessToken?.toJson()}');
});
},
child: const Text('Login'),
),
),
ElevatedButton(
onPressed: () {
_facebookSignIn.isLoggedIn.then((isLoggedIn) {
if (isLoggedIn) {
print('User logged in');
} else {
print('User is not login yet');
}
});
},
child: const Text('Check is user logged in'),
),
ElevatedButton(
onPressed: () {
_facebookSignIn.logOut().then((value) {
print('Logged out your facebook account');
});
},
child: const Text('Logout'),
),
ElevatedButton(
onPressed: () {
_facebookSignIn
.getUserData(
fields:
'id,name,first_name,last_name,email,middle_name,name_format,picture.width(800).height(800),short_name')
.then((value) {
print('User data ::: $value');
});
},
child: const Text('Get user data'),
),
ElevatedButton(
onPressed: () {
_facebookSignIn
.getUserDataAndMapToModel(
fields: 'id,'
'name,'
'first_name,'
'last_name,'
'email,'
'middle_name,'
'name_format,'
'picture,'
'short_name')
.then((value) {
print('User data model ::: ${value?.toJson()}');
});
},
child: const Text('Get user data and map to model'),
),
ElevatedButton(
onPressed: () {
_facebookSignIn.currentAccessToken.then((accessToken) {
print('Current access token ::: ${accessToken?.toJson()}');
});
},
child: const Text('Get current access token'),
),
ElevatedButton(
onPressed: () {
_facebookSignIn.reauthorizeDataAccess().then((result) {
print(
'Reauthorize data access status ::: ${result?.status}');
print(
'Reauthorize data access token ::: ${result?.accessToken?.toJson()}');
});
},
child: const Text('Reauthorize data access'),
),
],
),
),
),
);
}
}