flutter - 类型 'GeoPoint' 不是 flutter firestore 中类型 'String' 的子类型

标签 flutter dart google-cloud-firestore

我正在尝试 google maps flutter with firestore 但出了点问题。

这是我的代码

class StoreMap extends StatelessWidget {
  const StoreMap({
    Key key,
    @required this.documents,
    @required this.initialPosition,
    @required this.mapController,
  }) : super(key: key);

  final List<DocumentSnapshot> documents;
  final LatLng initialPosition;
  final Completer<GoogleMapController> mapController;

  @override
  Widget build(BuildContext context) {
    return GoogleMap(
      initialCameraPosition: CameraPosition(
        target: initialPosition,
        zoom: 12,
      ),
      markers: documents
          .map((document) => Marker(
                markerId: MarkerId(document['placeId']),
                icon: BitmapDescriptor.defaultMarkerWithHue(_pinkHue),
                position: LatLng(
                  document['location'].latitude,
                  document['location'].longitude,
                ),
                infoWindow: InfoWindow(
                  title: document['name'],
                  snippet: document['address'],
                ),
              ))
          .toSet(),
      onMapCreated: (mapController) {
        this.mapController.complete(mapController);
      },
    );
  }
}

类型“GeoPoint”不是类型“String”的子类型

Firestore 看起来像

enter image description here

最佳答案

问题看起来是MarkerId(document['placeID']),它需要是一个字符串。

您可以尝试使用 MarkerId(document['placeID'].toString()) 或根据标记的位置生成您自己的自定义字符串。

注意您的 placeId 而不是 placeID

关于flutter - 类型 'GeoPoint' 不是 flutter firestore 中类型 'String' 的子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56574178/

相关文章:

java - Firestore 无法将 java.lang.String 类型的值转换为日期

java - 访问flutter assets时出现File not Found异常

flutter - 使用 onPress 检索数据

flutter - 将 Intent Web url 转换为 Android Intent

asynchronous - 在 Dart 中,如何确保流更新在继续之前完成?

flutter 下拉失败断言行 620

ios - 在 Swift 中更新变量之前数组正在更新

Flutter:在数据库中插入数据列表的有效方法

flutter - 用 flutter canvas 在形状上切一个洞

javascript - Firestore 尚未返回任何记录,我在控制台中看到它们