更新时间:2022-05-23 22:44:02
如果用户使用电子邮件和密码注册,则可以选择更新 displayName
和 photoUrl
用户.
If a user signed up using email and password, there is an option to update displayName
and photoUrl
of the user.
// Suppose currentUser is the logged in FirebaseUser
currentUser.updateProfile(
UserUpdateInfo(
displayName: 'name',
photoUrl: '...',
),
),
如果从未执行过此操作,则 displayName
和 photoUrl
将返回 null
If this was never done displayName
and photoUrl
will return null
由于您在 users
集合中有数据,因此您将必须从该 document
中访问该数据,就像您访问其中的任何其他 document
消防站.
Since you have data in users
collection you'll have to access that data from that document
just like u access any other document
in firestore.
一种更好的方法是在注册期间接受 displayName
,这样您就可以更新该用户的 displayName
:
A better approach would be to accept displayName
during sign up so that u can update displayName
of that user:
FirebaseAuth.instance.createUserWithEmailAndPassword(
email: 'an email',
password: 'a password',
).then((newUser) {
newUser.updateProfile(
UserUpdateInfo(
displayName: 'name',
),
);
});
现在,您可以直接使用 currentUser.displayName
进行访问.
Now u can access using currentUser.displayName
directly.