【发布时间】:2019-01-17 07:05:34
【问题描述】:
我正在尝试更新我正在构建的应用程序用户的用户个人资料。用户信息存储在 firebase 中,应用程序在 android 上运行的 dart 中编码。
我已经尝试从https://firebase.google.com/docs/auth/web/manage-users 网站实现示例。
51 createUser() {
52 if (checkFields()) {
53 //Perform Login
54 var user = FirebaseAuth.instance.currentUser();
55 FirebaseAuth.instance
56 .createUserWithEmailAndPassword(email: _email, password: _password)
57 .then((user) {
58 var userUpdateInfo = new UserUpdateInfo();
59 user.updateProfile(userUpdateInfo)
.then((user) {
60 userUpdateInfo.displayName = _Firstname;
61 FirebaseAuth.instance
.currentUser()
.then((user) {
UserManagement().storeNewuser(user, context);
62 })
.catchError((e) {print(e);});
63 })
.catchError((e) {
64 print(e);
65 });
66 //UserManagement().storeNewuser(user, context);
67 Navigator.of(context).pop();
68 Navigator.of(context)
.pushReplacementNamed('/landingpage');
69 })
.catchError((e) {
70 print("ivlvvliyviv");
71 });
72 }
73 }
应用程序运行平稳,不会崩溃,但是当用户更新名字但在 firebase 上没有更改时,第 60 行假设更新 firebase 上的名字字段,这就是我添加名字字段的地方
Firestore.instance
.collection('/users')
.add({
'email': user.email,
'uid': user.uid,
'firstname': user.firstname,
【问题讨论】:
-
一旦创建 - 你只是想更新用户 -
displayName? -
'firstname': user.firstname这永远不会起作用 - Firebase 用户没有这样的字段。 -
是的,我想更新用户显示名,我该怎么做
-
我添加了关于更新的答案 -
User - displayName