[英]Flutter - how to trigger a function after the async function is completed
您好,我希望 addUserToFirestore() function 在上面的代碼執行完畢后觸發
Future<void> registerAccount(
String email,
String displayName,
String password,
void Function(FirebaseAuthException e) errorCallback) async {
try {
var credential = await FirebaseAuth.instance
.createUserWithEmailAndPassword(email: email, password: password);
await credential.user!.updateDisplayName(displayName);
addUserToFirestore();
} on FirebaseAuthException catch (e) {
errorCallback(e);
}
}
嘗試將您的代碼更改為:
await credential.user!.updateDisplayName(displayName)
.then((_) => addUserToFirestore());
這樣addUserToFirestore()
只會在updateDisplayName()
完成后觸發
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.