flutterfirebase-authenticationfacebook-authentication

Firebase Flutter Facebook auth , the getter 'token' isn't defined for the type 'AccessToken'


enter image description here

Future<User?> signInWithFacebook() async {
    try {
      // Trigger the Facebook Authentication flow
      final LoginResult result = await FacebookAuth.instance.login();

      if (result.status == LoginStatus.success) {
        final accessToken = result.accessToken!;
        
        print('AccessToken type: ${accessToken.runtimeType}');
        print('AccessToken properties: ${accessToken.toString()}');
        
        // Create a credential using the token
        final OAuthCredential credential = FacebookAuthProvider.credential(accessToken.token);

  
    return _auth.authStateChanges();
  }
}

no matter what i did. I couldn't resolve this issue

It just doesnt get the token. How can i resolve this man i am stuck here 2 hours. HOW HARD CAN IT BE


Solution

  • Change this:

    final OAuthCredential credential = FacebookAuthProvider.credential(accessToken.token);
    

    into this:

    final OAuthCredential credential = FacebookAuthProvider.credential(accessToken!.tokenString);
    

    The class AccessToken no longer has a property called token, instead now it's tokenString.

    You can check here:

    https://pub.dev/documentation/flutter_facebook_auth/latest/flutter_facebook_auth/AccessToken/tokenString.html