Firebase 如何在Flatter中获取firestore数据

Firebase 如何在Flatter中获取firestore数据,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,在initState()中调用readLocationData()时,我的代码出现此错误: 未处理的异常:“GeoPoint”类型不是“Iterable”类型的子类型 我不知道怎么修这个。My firebase Cloud Firestore有一个包含4个文档的列表,每个文档都有一个名为GeoPoint的GeoPoint字段,每个文档都有手动编码的纬度和经度 Future<void> readLocationData() async { var query = awa

在initState()中调用readLocationData()时,我的代码出现此错误:

未处理的异常:“GeoPoint”类型不是“Iterable”类型的子类型

我不知道怎么修这个。My firebase Cloud Firestore有一个包含4个文档的列表,每个文档都有一个名为
GeoPoint
GeoPoint
字段,每个文档都有手动编码的纬度和经度

  Future<void> readLocationData() async {


    var query = await Firestore.instance.collection('bakeries').getDocuments();

    List<Map<dynamic, dynamic>> mainList = List<Map<dynamic, dynamic>>();

    query.documents.forEach((doc) {

      List<Map<dynamic, dynamic>> values = List.from(doc.data['geopoint']);
      print('geopoint' + values.toString() +'\n');

    });

    for(var i=0; i < mainList.length; i++) {
      Map<dynamic, dynamic> map = mainList[i];
      GeoPoint geopoint = map['geopoint'];
  print(geopoint.latitude.toString()+','+ geopoint.longitude.toString());
  }

  }
Future readLocationData()异步{
var query=await Firestore.instance.collection('bakeries').getDocuments();
List mainList=List();
query.documents.forEach((doc){
列表值=列表源(文档数据['geopoint']);
打印('geopoint'+values.toString()+'\n');
});
对于(变量i=0;i
错误消息表明a不可编辑,这是正确的。我不确定您希望从(doc.data['geopoint'])返回什么


如果希望从
地理点
获取纬度和经度,则必须在代码中明确访问这些属性。但是我不确定你的
地图中的
键和
值会变成什么。

如果你能说出它调用的是哪一行,这将有助于诊断你的错误这是行“List values=List.from(doc.data['geopoint');”哈哈,我在打印这个答案的时候,你把它贴出来了,汉克斯!但是,如何访问代码中的纬度和经度呢?我已经试了好几天了,脑子都转不过来了。经度和纬度行吗?