facebook login is passing null

Viewed 149

i am trying to login with facebook and i keep getting null, and it will give uid but rest will be null

here is the error.

D/FirebaseAuth(30710): Notifying id token listeners about user ( p8rut85TnGdolVI5Oig0IBRSbqj1 ).
I/flutter (30710): ...........this is the error NoSuchMethodError: The method '[]' was called on null.
I/flutter (30710): Receiver: null
I/flutter (30710): Tried calling: []("id")

here is my code

the on click

GestureDetector(
                      onTap: ()async {
                        final progress = ProgressHUD.of(context);
                        progress?.showWithText('Loging in...');
                        try {
                          final facebook = await AuthenticationApi().signInFacebook();
                          if(facebook){
                            await checkDataFromDB();
                            progress?.dismiss();
                          }else{
                            progress?.dismiss();
                            await Flushbar(
                              title: 'Ops!',
                              message: 'Sign in not completed, Try again!!!',
                              duration: Duration(seconds: 3),
                            ).show(context);
                          }
                        } on PlatformException catch (err){
                          progress?.dismiss();
                          await Flushbar(
                            title: 'Ops!',
                            message: 'error ${err.code}',
                            duration: Duration(seconds: 3),
                          ).show(context);
                        } catch (e) {
                          print('...........this is the error $e');
                          progress?.dismiss();
                          await Flushbar(
                            title: 'Ops!',
                            message: 'error $e',
                            duration: Duration(seconds: 3),
                          ).show(context);
                        }
                      },
                      child: LoginBtn(
                        icon: FontAwesomeIcons.facebook,
                      ),
                    ),

here is the class

Future<bool> signInFacebook() async {
    var result =
    await facebookLogin.logIn(['email', 'public_profile']);

    if (result.status == FacebookLoginStatus.loggedIn) {
      FacebookAccessToken myToken = result.accessToken;
      AuthCredential credential =
      FacebookAuthProvider.credential(myToken.token);

      var user = await FirebaseAuth.instance.signInWithCredential(credential);
      return true;
    }

  }

here the output in firebase console

![the output]

thanks for helping

1 Answers

Make sure to enable the facebook login method on firebase, create your Facebook Development developer account and add the facebook Id on the android and iOS platform as directed by lib. For example on Android:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="facebook_application_id" translatable="false">1234567897654321</string>
    <string name="facebook_login_protocol_scheme" translatable="false">fb1234567897654321</string>
</resources>

e iOS em ios/Runner/Info.plist:

<key>FacebookAppID</key>
<string>1234567897654321</string>
Related