如何在Firestore槽Flutter中添加Geopoint,时间戳和对文档的引用

Tre*_*ree 1 firebase flutter google-cloud-firestore

在Firestore中设置基本类型非常容易。

但是我找不到如何使用Flutter Firestore插件构造Geopoint,Timestamp和其他文档参考。

您如何对设置Map<String,dynamic>为每个对象的默认数据进行内部分析?

任何帮助或例子吗?

Tre*_*ree 5

我在服务器上手动创建了一个对象,并将其放入我的flutter应用程序中。 在此处输入图片说明

对于TimeStamp,您可以DateTime直接从飞镖传递对象。

对于Geopoint,FireStrore插件内部有GeoPoint对象。

new GeoPoint(longitude: 3.4, latitude: 4.5) })
Run Code Online (Sandbox Code Playgroud)

对于另一个文档参考,您会将DocumentReference获取的值作为值传递给数据对象。


小智 5

要在 firebase 中创建或更新地理点,您可以直接使用对象 GeoPoint(Latitude, Longitude),此示例来自官方文档

CollectionReference users = FirebaseFirestore.instance.collection('users');

Future<void> updateUser() {
  return users
    .doc('ABC123')
    .update({'info.address.location': GeoPoint(53.483959, -2.244644)})
    .then((value) => print("User Updated"))
    .catchError((error) => print("Failed to update user: $error"));
}
Run Code Online (Sandbox Code Playgroud)