dart 我想保存ID本身包括在其他数据被保存

kokeuurv  于 2023-05-04  发布在  其他
关注(0)|答案(1)|浏览(111)

https://i.stack.imgur.com/GvVsx.png
我想将房间ID保存到右侧的房间详细信息中。

q3qa4bjr

q3qa4bjr1#

您需要先获取房间ID,以便将数据设置为该ID,如下所示

Future<void> addCategory(
    BuildContext context,
    String categoryName,
  ) async {
    bool hasConnection = await NetworkConn.isInternet();
    if (hasConnection) {
      String categoryId = category.doc().id;///this is the id
      return category.doc(categoryId).set({
        'id': categoryId,///this is the in feild 
        'CategoryName': categoryName,
        "AddedBy": user!.email,
        "CreatedAt: ": DateTime.now().toString(),
      }).then((value) {
        CustomDialog.showSuccessDialog(context, "Category Added");
      }).catchError((error) {
        Logger().e("Failed to add user: $error");
        CustomDialog.showErrorDialog(context, "Unable to add Category");
      });
    } else {
      CustomDialog.showErrorDialog(context, "Please Connect to Internet");
    }
  }

相关问题