您可以使用
setfunction代替
add。
这是完整的代码:
final CollectionReference postsRef = Firestore.instance.collection('/posts');var postID = 1;Post post = new Post(postID, "title", "content");Map<String, dynamic> postData = post.toJson();await postsRef.document(postID).setData(postData);希望对任何人有帮助。



