當用戶在“注冊頁面”上提交他們的資訊時,用戶應該有
- 在 Fire Store 中注冊的帳戶和
- 一個包含所有資訊的消防存盤檔案。
用戶帳戶注冊良好,但檔案永遠不會被創建。我沒有收到任何錯誤訊息,所以我嘗試使用除錯列印來找出哪里出了問題。
除錯列印:
>> login: signUp // this starts the signUp function
>> login: Start hideNewUserOverlay // hide overlay prints before signUp finishes
>> signUp: current user got // the following prints are from signUp
>> signUp: user.id = L8pD6tng5NTAACN7VygK93F6crg1
>> signUp: document creation code Start // then nothing happens after this
應該注冊用戶并創建檔案的未來: //這最終也會傳入名字/姓氏,這就是我使用這個函式的原因
Future<void> signUp(String email, String password) async {
try {
// ignore: unused_local_variable
UserCredential result = await auth.createUserWithEmailAndPassword(email: email, password: password); // <-- user account is created on first press
} catch (e) {
debugPrint('>> Authentication: create new user error');
}
user = auth.currentUser!;
debugPrint('>> signUp: current user got');
String userID = user.uid;
debugPrint('>> signUp: user.id = $userID'); // all debugs print out correctly here, even userID
debugPrint('>> signUp: document creation code Start');
await collectionReference.doc(userID).set({ // code does not run
'userID': userID,
'accountCreated': DateTime.now(),
'email': email,
});
debugPrint('>> Authentication: User Document Created');
}
注冊頁面:
onPressed: () {
debugPrint('>> login: signUp');
signUp(_email, _password); // this line should finish before the next debug statement is printed but it does not
debugPrint('>> login: Start hideNewUserOverlay'); // prints before signUp() is done
hideNewUserOverlay(); // this will close the Signup page
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) => const Nav(),
));
}
在代碼的底部,如果我路由到不同的類,檔案將被創建。導航()>>驗證()。奇怪的是,Verify 不接受任何用戶資訊。Verify() 有一個計時器,所以也許這與它有關?我認為這是因為在覆寫隱藏之前 signup() 函式沒有完成。也許 Nav() 需要初始化狀態?
uj5u.com熱心網友回復:
把await從回報的宣告中Future,使該行塊執行的其余部分。它并沒有然而,做任何其他的呼叫等待。
如果你想等到signUp完成,也可以await在那里使用:
await signUp(_email, _password);
這確實意味著您也需要將其標記onPressed為async方法。
如果這不是一個選項,您可以隨時使用then:
onPressed: () {
debugPrint('>> login: signUp');
signUp(_email, _password).then(() {
debugPrint('>> login: Start hideNewUserOverlay'); // prints before signUp() is done
hideNewUserOverlay(); // this will close the Signup page
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) => const Nav(),
));
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/408816.html
標籤:
上一篇:如何在容器旁邊有一個SingleScrollView
下一篇:Dart程式未退出
