Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Geopoint, timestamp and reference to a document in Firestore trough Flutter

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?

like image 798
Tree Avatar asked May 28 '18 22:05

Tree


People also ask

What is document reference in flutter?

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.


3 Answers

In the latest version of flutter a GeoPoint is created without named parameters.

GeoPoint(0, 0);

first argument => latitude

second argument => longitude

like image 197
Pedro Romão Avatar answered Sep 18 '22 05:09

Pedro Romão


I created manually an object on the server and got it inside my flutter app. enter image description here

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.

like image 18
Tree Avatar answered Oct 13 '22 08:10

Tree


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"));
}
like image 4
Ayoub Arroub Avatar answered Oct 13 '22 08:10

Ayoub Arroub