Flutter: исключение базы данных Firebase с входом в Facebook - PullRequest
0 голосов
/ 04 августа 2020

Я выполнял этот вход в Facebook и пытался загрузить свои данные в данные firebase, и я обнаружил это исключение. Моя программа все еще работает, но продолжает выдавать это исключение. Почему и как я могу это исправить?

Future loginWithFacebook(BuildContext context) async {
    try {
      FacebookLogin facebookLogin = FacebookLogin();

      final FacebookLoginResult result =
          await facebookLogin.logIn(['email', 'public_profile']);
      print('Result status - ${result.status.toString()}');
      //result.accessToken.
      final token = result.accessToken.token;

      print('Facebook token userID : ${result.accessToken.permissions}');
      final graphResponse = await http.get(
          'https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email&access_token=${token}');

      final profile = jsonDecode(graphResponse.body);
      print(profile);

      // user locale
      Locale myLocale = Localizations.localeOf(context);
      String locale = myLocale.languageCode;
      print('Langauge is $locale');

      final credential = FacebookAuthProvider.getCredential(accessToken: token);

      FirebaseUser user = (await _auth.signInWithCredential(credential)).user;

      print("Facebase Facebook user ID : ${user.uid}");

      await User_DatabaseService(uid: user.uid).updateUserData(
        user.email,
        locale,
        user.displayName,
        token,
        user.uid,
      );
      return _userFromFirebaseUser(user);
    } catch (e) {
      print(e.toString());
      return null;
    }
  }

Это произошло после того, как я включил эту часть ниже

await User_DatabaseService(uid: user.uid).updateUserData(
    user.email,
    locale,
    user.displayName,
    token,
    user.uid,
  );

Исключение:

Exception has occurred.
    FlutterError (setState() called after dispose(): _LoginScreenState#58b72(lifecycle state: defunct, not mounted)
    This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
    The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
    This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().)
...