It is fairly straightforward hot to set basic types inside Firestore.
But I cannot find how to construct Geopoint, Timestamp and another document reference with flutter Firestore plugin.
What do you assing inside data that you set to the coollection Map<String,dynamic>
for each object?
Any help or examples?
A DocumentReference refers to a document location in a FirebaseFirestore database and can be used to write, read, or listen to the location. The document at the referenced location may or may not exist. A DocumentReference can also be used to create a CollectionReference to a subcollection. Annotations. @sealed.
In the latest version of flutter a GeoPoint is created without named parameters.
GeoPoint(0, 0);
first argument => latitude
second argument => longitude
I created manually an object on the server and got it inside my flutter app.
For TimeStamp you can pass DateTime
object directly from dart.
For Geopoint there is GeoPoint object inside Firestore plugin.
new GeoPoint(longitude: 3.4, latitude: 4.5) })
For another document reference, you would pass DocumentReference
that you retrieved as a value to the data object.
To create or update geopoint in firebase you can use the object GeoPoint(Latitude, Longitude) directly, this example from official documentation
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"));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With