firebase - 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”。
解决方案
我建议查看FlutterFire的升级指南,以及更新的参考文档firebase_auth
library。
例如,现在在对象上定义了updateProfile
方法和reload
方法以及uid
属性User
。
同一个User
对象也有一个updateProfile
方法,它将displayName
用作可选的命名参数。
推荐阅读
- r - 规范化 R 中的俄语字符
- python - django 1.11 中 SelectDateWidget 的空选项
- python - Python - 将字符串转换为简单的 YYYY 日期格式
- memory-management - 内存管理单元如何将虚拟地址映射到物理地址
- python - Python - PyPDF2 遗漏了大量文本。Windows上有任何替代方案吗?
- java - Java线程:3个Java线程之间的通信
- python - 对于 python 3,我不断得到一个带有新行的字符串值
- scala - 引起:com.fasterxml.jackson.databind.JsonMappingException:不兼容的杰克逊版本:2.8.9
- c++ - system_clock 和 ctime 导致 C++ 中的未初始化值内存错误
- java - 何时在 Java 中分配 Random 对象