【问题标题】:Flutter Firebase Auth new update [duplicate]Flutter Firebase Auth 新更新 [重复]
【发布时间】:2021-02-01 14:59:12
【问题描述】:

我有一个带有“旧”firebase 身份验证小部件的工作应用程序。 现在身份验证已更新,没有任何工作了。

你能帮我修一下吗????

这是整个小部件:

import 'package:firebase_auth/firebase_auth.dart';

class AuthService {
  final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;

  // ignore: deprecated_member_use
  Stream<String> get onAuthStateChanged => _firebaseAuth.onAuthStateChanged.map(
        (User user) => user?.uid,
      );

  //Email & Password Sign up
  Future<String> createUserWithEmailAndPassword(
      String email, String password, String name) async {
    final currentUser = await _firebaseAuth.createUserWithEmailAndPassword(
      email: email,
      password: password,
    );

    //Update the Username
    var userUpdateInfo = UserUpdateInfo();
    userUpdateInfo.displayName = name;
    await currentUser.updateProfile(userUpdateInfo);
    await currentUser.reload();
    return currentUser.uid;
  }

//Email Password Sign In
  Future<String> signInWithEmailAndPassword(
      String email, String password) async {
    return (await _firebaseAuth.signInWithEmailAndPassword(
            email: email, password: password))
        .user
        .uid;
  }

//Sign Out
  signOut() {
    return _firebaseAuth.signOut();
  }
}

小部件的这部分不再起作用:

    //Update the Username
    var userUpdateInfo = UserUpdateInfo();
    userUpdateInfo.displayName = name;
    await currentUser.updateProfile(userUpdateInfo);
    await currentUser.reload();
    return currentUser.uid;

以下是错误:

错误:没有为“AuthService”类型定义方法“UserUpdateInfo”。 错误:没有为“UserCredential”类型定义方法“updateProfile”。 错误:没有为“UserCredential”类型定义“重新加载”方法。 错误:没有为“UserCredential”类型定义 getter 'uid'。

【问题讨论】:

    标签: firebase flutter dart firebase-authentication


    【解决方案1】:

    我建议查看 FlutterFire 的 upgrade guide,以及更新后的 reference documentation the firebase_auth library。

    例如,updateProfile method 和 reload method 以及 uid property 现在在 User 对象上定义。

    同样的User 对象还有一个updateProfile method,它将displayName 作为一个可选的命名参数。

    【讨论】:

      【解决方案2】:

      您应该降低库的版本或通过该库的新文档来重构您的代码。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-11-24
        • 1970-01-01
        • 1970-01-01
        • 2017-01-20
        • 1970-01-01
        • 2020-05-24
        • 2020-12-26
        • 1970-01-01
        相关资源
        最近更新 更多