小编Han*_*nna的帖子

Firestore / Flutter - 如何获取文档 ID?

这是我的代码

Future _save() async {

final StorageReference storageRef = FirebaseStorage.instance.ref().child('product/'+nameController.text+'.jpg');
final StorageUploadTask task = storageRef.putFile(_image);
StorageTaskSnapshot taskSnapshot = await task.onComplete;
String downloadUrl = await taskSnapshot.ref.getDownloadURL();
StorageMetadata created = await taskSnapshot.ref.getMetadata();

Firestore.instance.collection('product').document()
    .setData({
  'name': nameController.text,
  'price': int.tryParse(priceController.text),
  'description': descriptionController.text,
  'creator': widget.user.uid,
  'created': DateTime.fromMillisecondsSinceEpoch(created.creationTimeMillis, isUtc: true).toString(),
  'modified': DateTime.fromMillisecondsSinceEpoch(created.updatedTimeMillis, isUtc: true).toString(),
  'url': downloadUrl,
  'id': //I want to set document Id here //
});
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能得到这个随机生成的文档的 ID?感谢您的帮助

firebase flutter google-cloud-firestore

11
推荐指数
3
解决办法
2万
查看次数

标签 统计

firebase ×1

flutter ×1

google-cloud-firestore ×1