firebase - Flutter/Dart/Firestore:如何将地图列表添加到 Firebase?
问题描述
对不起,如果这是一个重复的问题。我尝试过四处搜索,但无法找到解决此问题的方法。
我有一个飞镖地图列表。例如:
List<Map<String, String>> questionsAndAnswers = [{'questions':'How many?', 'answer':'five'},
{'question':'How much?', 'answer':'five dollars'}];
我想将此地图列表存储到 Firestore 中,并且我已经看到您可以手动创建地图数组,但我想以编程方式执行此操作。
有谁知道如何做到这一点?我已经尝试过_firestore.collection('Quiz').add(questionsAndAnswers);
,但这还没有成功,我收到以下错误:The argument type 'List<Map<String, String>>' can't be assigned to the parameter type 'Map<String, dynamic>'.
预先感谢您的所有帮助。
解决方案
假设这是您的地图列表:
List<Map<String, String>> myData = [
{'questions': 'How many?', 'answer': 'five'},
{'question': 'How much?', 'answer': 'five dollars'},
];
将其添加到
收藏:
FirebaseFirestore.instance .collection('collection') .add({'some_key': myData});
文件:
FirebaseFirestore.instance .doc('collection/document') .set({'some_key': myData});
推荐阅读
- javascript - 如何通过点击id打开模态
- kubernetes - JupyterHub setup- CrashLoopBackOff 中的 Kubernetes hub pod
- javascript - 如何在反应中使用axios(post)
- xcode - NSWindow 中的 NSToolbar 无法正确显示
- php - 未显示警告或通知
- c++ - LibSSH:在会话中与脚本/bash 交互
- scala - 如何在scala中将数组转换为字符串
- postgresql - 如何更新 dockerized postgresql 数据库中的模式?
- r - 匹配文本中的确切单词列表
- excel - 如何解决导出 excel laravel 中的“函数 App\Exports\ItemsExport::__construct(), 0 传递的参数太少”?