您可以尝试以下方法:
documentReference docRef = await Firestore.instance.collection('gameLevels').add(map);print(docRef.documentID);由于add()方法创建新文档并自动生成ID,因此您无需显式调用document()方法
或者,如果您想使用“ then”回调,请尝试以下操作:
final collRef = Firestore.instance.collection('gameLevels'); documentReferance docReference = collRef.document(); docReferance.setData(map).then((doc) { print('hop ${docReferance.documentID}'); }).catchError((error) { print(error); });


