[英]Update a field in the last document in Firestore collection Flutter
[英]Flutter Firestore update document name inside of collection
我正在嘗試在我的 Flutter 應用程序中添加更新用戶名集合中文檔名稱的功能。 這是我上傳的 function:
Future<void> updateUsername() {
// Add a new user inside our the Usernames Collection. This is useful to check for username availablilty.
return usernames
.doc(username)
.set({
'uid': uid,
'timeCreated': DateTime.now(),
})
.then((value) => print("Username Added"))
.catchError((error) => print("Failed to add username: $error"));
}
Firestore 中沒有重命名文檔的選項。 最常用的方法是用新名稱和舊文檔中的數據創建一個新文檔,然后刪除舊文檔。
看看這里: 我可以在 Firestore 中更改文檔的名稱嗎?
還有一個建議,如果您不打算在用戶名文檔中放入任何數據,那么制作一個名為“用戶名”的文檔並將它們添加到那里,這將有助於減少閱讀量......除非你知道你正在做。
Padding( padding: const EdgeInsets.only(left: 15), child: TextFormField( controller: _fname, // onTap: () { // bottomsheet(context); // }, decoration: InputDecoration(border: InputBorder.none, contentPadding: CONTENTPADDING, suffixIcon: Image.asset('assets/images/pencil.png', color: kSubTitle, scale: 2.5, ), labelText: 'firstName', labelStyle: TextStyle( color: kSubTitle, fontWeight: FontWeight.w400, fontSize: 16), hintText: fname == ''? _auth.currentUser.displayName.toString(): '$fname', hintStyle: TextStyle( 顏色: kTextFieldColor, 字體大小: 14, 字體粗細: FontWeight.w300), focusBorder : UnderlineInputBorder(borderSide: BorderSide(顏色: Colors.grey), ), )), ),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.