首页 > 解决方案 > Flutter Firebase 身份验证新更新

问题描述

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

你能帮我修一下吗???

这是整个小部件:

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”类型定义吸气剂“uid”。

标签: firebaseflutterdartfirebase-authentication

解决方案


我建议查看FlutterFire的升级指南,以及更新的参考文档firebase_authlibrary

例如,现在在对象上定义了updateProfile方法reload方法以及uid属性User

同一个User对象也有一个updateProfile方法,它将displayName用作可选的命名参数。


推荐阅读