flutter_facebook_auth 0.0.1 copy "flutter_facebook_auth: ^0.0.1" to clipboard
flutter_facebook_auth: ^0.0.1 copied to clipboard

outdated

A new Flutter plugin to Login with Facebook

example/lib/main.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  dynamic _userData;

  @override
  void initState() {
    super.initState();
    _checkIfIsLogged();
  }

  _checkIfIsLogged() async {
    final accessToken = await FacebookAuth.isLogged();
    if (accessToken != null) {
      print("accessToken: ${accessToken}");
      // now you can call to  FacebookAuth.getUserData();
      final userData = await FacebookAuth.getUserData();
      // final userData = await FacebookAuth.getUserData(fields:"email,birthday");
      setState(() {
        _userData = userData;
      });
    }
  }

  _login() async {
    final result = await FacebookAuth.login();
    // final result = await FacebookAuth.login(permissions:['email','user_birthday']);
    print("login result ${result.toString()}");
    if (result['status'] == 200) {
      print("accessToken: ${result['accessToken']}");
      // get the user data
      final userData = await FacebookAuth.getUserData();
      // final userData = await FacebookAuth.getUserData(fields:"email,birthday");
      print("userData: ${userData.toString()}");
      setState(() {
        _userData = userData;
      });
    } else if (result['status'] == 403) {
      print("login cancelled");
    } else {
      print("login failed");
    }
  }

  _logOut() async {
    await FacebookAuth.logOut();
    setState(() {
      _userData = null;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Facebook Auth'),
        ),
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Text(_userData != null ? _userData.toString() : "NO LOGGED"),
            CupertinoButton(
                color: Colors.blue,
                child: Text(
                  _userData != null ? "LOGOUT" : "LOGIN",
                  style: TextStyle(color: Colors.white),
                ),
                onPressed: _userData != null ? _logOut : _login),
          ],
        ),
      ),
    );
  }
}
1344
likes
0
pub points
100%
popularity

Publisher

verified publishermeedu.app

A new Flutter plugin to Login with Facebook

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on flutter_facebook_auth