0

i have been trying to login with facebook authentication with is this plugin

here the facebook plugin

but i keep getting this error after given me a token listeners about the user

    D/FirebaseAuth(16644): Notifying id token listeners about user ( 7fJCaA1cplgINtOJuvi2AYxd4dG3 ).
    E/flutter (16644): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: NoSuchMethodError: Class 'NoSuchMethodError' has no instance getter 'code'.
    E/flutter (16644): Receiver: Instance of 'NoSuchMethodError'
    E/flutter (16644): Tried calling: code
E/flutter (16644): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
E/flutter (16644): #1      LoginState.build.<anonymous closure>.<anonymous closure> (package:FaithMeetsLove/view/login.dart:157:49)
E/flutter (16644): <asynchronous suspension>
E/flutter (16644): 

here is my code

class authenticationApi{
  Future<bool> signInFacebook() async {
    try {
      final result = await facebookLogin.logIn(['email', 'public_profile']);
      switch (result.status) {
      case FacebookLoginStatus.loggedIn:
        final token = result.accessToken.token;
        final credential =
            FacebookAuthProvider.credential(token);
       final  user = (await auth.signInWithCredential(credential)).user;
       return true;
        break;
        case FacebookLoginStatus.cancelledByUser:
        break;
        case FacebookLoginStatus.error:
        print(".....Here is Status Error...........${result.errorMessage}");
        break;
    }
      return true;
    } catch (error) {
      print('Error ${error.code}');
      return false;
    }
  }
}

then i call it in my login.dart

 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) {
                          progress?.dismiss();
                          await Flushbar(
                            title: 'Ops!',
                            message: 'error ${e.code}',
                            duration: Duration(seconds: 3),
                          ).show(context);
                        }
                      },
                      child: LoginBtn(
                        icon: FontAwesomeIcons.facebook,
                      ),
                    ),

i am having a hard time to locate the error is coming from..

thanks

Gbenga B Ayannuga
  • 2,407
  • 3
  • 17
  • 38
  • The problem is here `print('Error ${error.code}');`. Why do you think this execption has a field as `code`? Doesn't seem like you have any custom exception in your code. Probabaly `print('Error ${error.messgae}');` is what you are looking for? – Sisir May 11 '21 at 18:25
  • Ignoring header X-Firebase-Locale because its value was null. i am getting this in the console. and is passing null to firestore – Gbenga B Ayannuga May 11 '21 at 18:39

1 Answers1

1

The error is in login.dart , 157:49

Check those lanes

Probably ${e.code} or ${err.code} doesn't have "code". Try put a breakpoint there and see what has e and err

Put it exactly here: await Flushbar(

Otherwise won't stop

Dani Roman
  • 359
  • 1
  • 7