Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter Map<String, dynamic>: Issues to get data from Firestore

I’m trying the get data from Firestore but I have a issues on Map<String, dynamics>. Any idea how to fix this issues?

    final QuerySnapshot result = await firestore.collection('markers').get();
    final List<DocumentSnapshot> documents = result.docs;
    int count = 0;
    documents.forEach((data) {
    Map<String, dynamic> datos = data.data;
      GeoPoint tmp = datos['position'];
      if (count < int.parse(data.id)) count = int.parse(data.id);
      final MarkerId markerId = MarkerId(data.id);
      LatLng point = LatLng(tmp.latitude, tmp.longitude);
      final Marker marker = Marker(
          markerId: markerId,
          position: point,
          infoWindow: InfoWindow(title: 'Id: ' + data.id),
          onTap: () {
            _onTapped(markerId);
          },
          icon: BitmapDescriptor.defaultMarkerWithHue(
              BitmapDescriptor.hueBlue));
      _markers[markerId] = marker;
    });
    _markerIdCounter = count + 1;
    setState(() {});
  }```

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

        final QuerySnapshot result = await firestore.collection('markers').get();
        final List<DocumentSnapshot> documents = result.docs;
        int count = 0;
        documents.forEach((data) {
// I changed this line
        Map<String, dynamic> datos = data.data() as Map<String, dynamic>;
          GeoPoint tmp = datos['position'];
          if (count < int.parse(data.id)) count = int.parse(data.id);
          final MarkerId markerId = MarkerId(data.id);
          LatLng point = LatLng(tmp.latitude, tmp.longitude);
          final Marker marker = Marker(
              markerId: markerId,
              position: point,
              infoWindow: InfoWindow(title: 'Id: ' + data.id),
              onTap: () {
                _onTapped(markerId);
              },
              icon: BitmapDescriptor.defaultMarkerWithHue(
                  BitmapDescriptor.hueBlue));
          _markers[markerId] = marker;
        });
        _markerIdCounter = count + 1;
        setState(() {});
      }`
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading