我試圖在我的小部件樹中呼叫一個 future 來將我的 userSetup 類寫入我的 Firestore 資料庫。我在運行我的代碼時沒有出現錯誤,但它不執行該函式,并且沒有任何內容寫入我的資料庫。我想知道如何糾正這個問題,所以當我按下按鈕時,它會寫入我的資料庫
這是我的用戶設定:
Future<void> userSetup(final String username, final String displayName,
final String profilePhoto, final String bio, final String bioLink) async {
CollectionReference users = FirebaseFirestore.instance.collection('users');
FirebaseAuth auth = FirebaseAuth.instance;
String uid = auth.currentUser!.uid.toString();
await users.add({
'uid': uid,
'displayName': displayName,
'username': username,
'profilePhoto': profilePhoto,
'bio': bio,
'bioLink': bioLink
});
return;
}
這是我的按鈕:
ElevatedButton(
style: TextButton.styleFrom(
backgroundColor: Colors.blue,
),
onPressed: () => userSetup(username, displayName, profilePhoto, bio, bioLink),
uj5u.com熱心網友回復:
嘗試這個:
Future userSetup(final String username, final String displayName,
final String profilePhoto, final String bio, final String bioLink) async {
CollectionReference users = FirebaseFirestore.instance.collection('users');
FirebaseAuth auth = FirebaseAuth.instance;
String uid = auth.currentUser!.uid.toString();
return await users.add({
'uid': uid,
'displayName': displayName,
'username': username,
'profilePhoto': profilePhoto,
'bio': bio,
'bioLink': bioLink
});
編輯:嘗試創建一個物件,然后將其作為引數傳遞給您的函式:
class UserInfo {
final String username;
final String displayName;
...
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/363622.html
標籤:火力基地 扑 镖 谷歌云firestore
