简体   繁体   English

Flutter/Dart/Firestore:如何将地图列表添加到 firebase?

[英]Flutter/Dart/Firestore: How can I add a list of maps to firebase?

Sorry if this is a repeated question.对不起,如果这是一个重复的问题。 I have tried searching around but have been unable to find a solution to this problem.我尝试过四处搜索,但无法找到解决此问题的方法。

I have a list of maps in dart.我在 dart 中有一个地图列表。 For example:例如:

List<Map<String, String>> questionsAndAnswers = [{'questions':'How many?', 'answer':'five'},
{'question':'How much?', 'answer':'five dollars'}];

I would like to store this list of maps into firestore and I have seen that you can manually create an array of maps but I would like to do this programmatically.我想将此地图列表存储到 Firestore 中,并且我已经看到您可以手动创建地图数组,但我想以编程方式执行此操作。

在此处输入图像描述

Does anyone know how this can be achieved?有谁知道如何做到这一点? I've tried _firestore.collection('Quiz').add(questionsAndAnswers);我试过_firestore.collection('Quiz').add(questionsAndAnswers); but this hasn't been successful and I'm receiving the following error: The argument type 'List<Map<String, String>>' can't be assigned to the parameter type 'Map<String, dynamic>'.但这并不成功,我收到以下错误: The argument type 'List<Map<String, String>>' can't be assigned to the parameter type 'Map<String, dynamic>'.

Say this is your list of map:假设这是您的 map 列表:

List<Map<String, String>> myData = [
  {'questions': 'How many?', 'answer': 'five'},
  {'question': 'How much?', 'answer': 'five dollars'},
];

Adding it to a将其添加到

  • Collection :收藏

     FirebaseFirestore.instance.collection('collection').add({'some_key': myData});
  • Document :文件

     FirebaseFirestore.instance.doc('collection/document').set({'some_key': myData});

暂无
暂无

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

相关问题 flutter、Firebase Firestore 我无法在列表中添加元素 - flutter, Firebase Firestore I can't add element in the list 如何将 displayName 添加到 Firebase 用户? (颤振/飞镖) - How can I add the displayName to the Firebase user? (Flutter/Dart) 如何在 firestore 中使用 .where() 查询在不同屏幕之间导航? Flutter, Dart, Firebase - How can I use the .where() query in firestore to navigate between different screens? Flutter, Dart, Firebase 在 Dart/Flutter 中,如何查看 Firestore 数据库中是否没有 Collection? - In Dart/Flutter, how can I find out if there is no Collection in the Firestore database? 使用Firebase的Firestore时,如何验证列表中的项目或地图? - How can I validate Items or Maps in a List when using Firebase's Firestore? How do I use Firebase.dart with Firebase Emulators FireStore db in a Flutter Web app? - How do I use Firebase.dart with Firebase Emulators FireStore db in a Flutter Web app? Flutter、Dart、Firestore:如何将从 firestore 检索到的用户数据发送到不同的屏幕? - Flutter, Dart, Firestore: How can I send user data retrieved from firestore to a different screen? 我如何在 flutter 和 firebase firestore 中制作价格范围过滤器 - How can i make price range filter in flutter and firebase firestore Flutter:如何从 Firestore 的 Firebase 存储中获取 URL - Flutter: How Can I Get URL From Firebase Storage In Firestore 我如何从 Firebase FireStore 获取图像到 carouselSlider Flutter - How can i fetch image from Firebase FireStore into carouselSlider Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM