繁体   English   中英

从 flutter 添加数组到 firebase 中的文档

[英]Adding an array to a document in firebase from flutter

我正在尝试在其文档中添加一个包含两个值的新集合,一个是字符串,另一个是数组。 当我添加没有数组的字符串时它起作用了,所以我的问题是数组。 这是我写的设置新收藏的function

void addCategory({required String addedCategory, required List tags}) {
  FirebaseFirestore.instance.collection("Category").doc(addedCategory).set({
    'name': addedCategory,
    'Tags': [tags]
  }).then((value) {
    emit(CategoryAdded());
  });
}

这就是召唤

UserCubit.get(context).addCategory(
  addedCategory: 'Resturants', tags: ['Italian', 'Romanian']
);

如果有人可以提供帮助,我将不胜感激。

您的标签已经是一个列表,不应作为list<list>发送

void addCategory({required String addedCategory, required List tags}) {
  FirebaseFirestore.instance.collection("Category").doc(addedCategory).set({
    'name': addedCategory,
    'Tags': [tags], // remove this line
    'Tags': tags,   // add this line
  }).then((value) {
    emit(CategoryAdded());
  });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM