Flutter sign in with facebook

400

I learned from github it's an error in the package or sdk or ....

But for IOS, it works if you use this:

final fbLogin =FacebookLogin();
fbLogin.loginBehavior = FacebookLoginBehavior.webViewOnly;
Share:
400
Karel Debedts
Author by

Karel Debedts

Updated on December 16, 2022

Comments

  • Karel Debedts
    Karel Debedts over 1 year

    I'm trying to sign my users in with facebook. Therefor, I use this code:

     FacebookLoginResult facebookLoginResult = await _handleFBSignIn();
            final accessToken = facebookLoginResult.accessToken.token;
            if (facebookLoginResult.status == FacebookLoginStatus.loggedIn) {
              setState(() {
                isSaving = true;
              });
    
              final facebookAuthCred =
                  FacebookAuthProvider.getCredential(accessToken: accessToken);
              final user =
                  await firebaseAuth.signInWithCredential(facebookAuthCred);
    
              final graphResponse = await http.get(
                  'https://graph.facebook.com/v4.0/me?fields=name,first_name,last_name,friends,email&access_token=$accessToken');
              final profile = jsonDecode(graphResponse.body);
    
              if (profile['id'] != null) {
                setState(() {
                  facebookID = profile['id'];
                });
              }
    
      Future<FacebookLoginResult> _handleFBSignIn() async {
        FacebookLogin facebookLogin = FacebookLogin();
        FacebookLoginResult facebookLoginResult =
            await facebookLogin.logInWithReadPermissions(['email', 'user_friends']);
        switch (facebookLoginResult.status) {
          case FacebookLoginStatus.cancelledByUser:
            print("Cancelled");
            break;
          case FacebookLoginStatus.error:
            print("error");
            break;
          case FacebookLoginStatus.loggedIn:
            print("Logged In");
            break;
        }
        return facebookLoginResult;
      }
    

    This works perfectly on android, but on ios I get an error.

    flutter: Cancelled
    [VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The getter 'token' was called on null.
    Receiver: null
    

    So I'm assuming it has something to do with my info.plist because android doesn't have the problem. I looked in my info.plist but can't find anything...

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>CFBundleDevelopmentRegion</key>
        <string>$(DEVELOPMENT_LANGUAGE)</string>
        <key>CFBundleExecutable</key>
        <string>$(EXECUTABLE_NAME)</string>
        <key>CFBundleIdentifier</key>
        <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
        <key>CFBundleInfoDictionaryVersion</key>
        <string>6.0</string>
        <key>CFBundleName</key>
        <string>drinkm8</string>
        <key>CFBundlePackageType</key>
        <string>APPL</string>
        <key>CFBundleShortVersionString</key>
        <string>$(FLUTTER_BUILD_NAME)</string>
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
        <string>$(FLUTTER_BUILD_NUMBER)</string>
        <key>LSRequiresIPhoneOS</key>
        <true/>
        <key>NSAppTransportSecurity</key>
        <dict>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
        </dict>
        <key>NSCameraUsageDescription</key>
        <string>Hiermee kunt u een verhaal maken</string>
        <key>NSContactsUsageDescription</key>
        <string>Your prompt</string>
        <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
        <string>Always/When in use description</string>
        <key>NSLocationAlwaysUsageDescription</key>
        <string>Can I haz location always?</string>
        <key>NSLocationWhenInUseUsageDescription</key>
        <string>This app needs access to location when open.</string>
        <key>NSMicrophoneUsageDescription</key>
        <string>Hiermee kunt u een verhaal maken</string>
        <key>NSMotionUsageDescription</key>
        <string>Motion Usage Description</string>
        <key>NSPhotoLibraryUsageDescription</key>
        <string>Hiermee kunt u een foto selecteren</string>
        <key>NSPhotoLibraryAddUsageDescription</key>
        <string>Hiermee kunt u een foto opslaan</string>
        <key>UIBackgroundModes</key>
        <array>
            <string>fetch</string>
            <string>location</string>
            <string>remote-notification</string>
        </array>
        <key>UILaunchStoryboardName</key>
        <string>LaunchScreen</string>
        <key>UIMainStoryboardFile</key>
        <string>Main</string>
        <key>UISupportedInterfaceOrientations</key>
        <array>
            <string>UIInterfaceOrientationPortrait</string>
            <string>UIInterfaceOrientationLandscapeLeft</string>
            <string>UIInterfaceOrientationLandscapeRight</string>
        </array>
        <key>UISupportedInterfaceOrientations~ipad</key>
        <array>
            <string>UIInterfaceOrientationPortrait</string>
            <string>UIInterfaceOrientationPortraitUpsideDown</string>
            <string>UIInterfaceOrientationLandscapeLeft</string>
            <string>UIInterfaceOrientationLandscapeRight</string>
        </array>
        <key>FirebaseAppDelegateProxyEnabled</key>
        <string>NO</string>
        <key>UIViewControllerBasedStatusBarAppearance</key>
        <false/>
        <key>CFBundleURLTypes</key>
        <array>
            <dict>
                <key>CFBundleTypeRole</key>
                <string>Editor</string>
                <key>CFBundleURLSchemes</key>
                <array>
                    <!-- TODO Replace this value: -->
                    <!-- Copied from GoogleService-Info.plist key REVERSED_CLIENT_ID -->
                    <string>com.googleusercontent.apps.myappid</string>
                    <string>fb4856myappid</string>
                </array>
            </dict>
        </array>
        <key>FacebookAppID</key>
        <string>4856myappid</string>
        <key>FacebookDisplayName</key>
        <string>DRINKM8</string>
        <key>LSApplicationQueriesSchemes</key>
        <array>
            <string>fbapi</string>
            <string>fb-messenger-share-api</string>
            <string>fbauth2</string>
            <string>fbshareextension</string>
        </array>
        <key>io.flutter.embedded_views_preview</key>
        <string>YES</string>
    </dict>
    </plist>
    

    Is there a step I missed to install FB for ios (I only edited my info.plist and added fb sign in to the pubspec yaml)?

    Thanks in advance!