从 Firestore 文档快照中映射 GeoPoint

时间:2021-03-17 19:00:24

标签: firebase flutter dart google-cloud-firestore geopoints

我正在尝试映射从 Firebase Firestore 读取的 GeoPoint 类型。 数据是从 Firestore 读取的,我在工厂的地图对象中获取了我的字段 geoPoint。 我收到一个错误,说 _TypeError (type '_InternalLinkedHashMap' is not a subtype of type 'GeoPoint') 当它尝试映射 ['geoPoint']

如果我继续执行,它确实会在 GeoPoint 类型中设置,但是这个错误只在我第一次阅读文档时发生,之后它可以工作,知道会发生什么吗?

import 'package:cloud_firestore/cloud_firestore.dart';

class RestaurantModel {
  final String id;
  final String name;
  final String logoURL;
  final String headerImage;
  final String phone;
  final String address;
  final String zipCode;
  final String town;
  final String website;
  final String eMail;
  final String aboutUs;
  final GeoPoint geoPoint;
  bool isExpanded = false;

  RestaurantModel({
    this.id,
    this.name,
    this.logoURL,
    this.headerImage,
    this.phone,
    this.address,
    this.zipCode,
    this.town,
    this.website,
    this.eMail,
    this.aboutUs,
    this.geoPoint,
  });

  factory RestaurantModel.fromMap({Map<String, dynamic> map, String docId}) {
    if (map == null) return null;

    return RestaurantModel(
        id: docId ?? map['id'],
        name: map['name'],
        logoURL: map['logoUrl'],
        headerImage: map['headerImage'] ?? '',
        phone: map['phone'],
        address: map['address'],
        zipCode: map['zipCode'],
        town: map['town'],
        website: map['website'],
        eMail: map['eMail'],
        aboutUs: map['aboutUs'] ?? '',
        geoPoint: map['geoPoint'],
        );
  }
}

0 个答案:

没有答案