The reload()
method is asynchronous and returns a Future<void>
. You should use the await
keyword to wait for a future to complete, see here.
It is not 100% clear to me why you need to use the reload()
method. Since you use the displayName
property in your code, is it because , in your app, this property is frequently changing? I would kindly suggest that you read in this SO answer the explanations on why one should use this method: "Calling reload()
reloads that user's profile data from the server".
So, if it appears that you really need to use this method, you could do something along the following lines:
void navigate() async {
if (_auth.currentUser != null) {
await _auth.currentUser.reload();
// continue your business logic here
// For example
if (_auth.currentUser.isEmailVerified) {
// Navigate to ...
}
} else {...}
}
Note that, as explained in the FlutterFire doc, you could alternatively use the userChanges()
method: "This stream
provides realtime updates to the User
class without having to call reload()
, such as when credentials are linked, unlinked and when the user's profile is updated".
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…