beerstorm-net / GeoFlutterFire2

🔥GeoFlutterFire2🔥 is an open-source library that allows you to store and query firestore documents based on their geographic location.
https://pub.dev/packages/geoflutterfire2
MIT License
14 stars 34 forks source link

Using GeoFirePoint with json serializable? #18

Open giorgio79 opened 1 year ago

giorgio79 commented 1 year ago

Anyone uses json serializable with GeoFlutterFire's GeoFirePoint?

I suspect we would need a custom JsonConverter for the data? Any tips or code samples?

The GeoPointConverter here works fine https://stackoverflow.com/questions/61707320/how-to-serialize-geopoint-using-dart-json-serializable-package , but here we have geohash too

emiliodallatorre commented 10 months ago

Hi @giorgio79, it's not that difficult.

You can just set a custom fromJson / toJson on the field of your serializable model. For instance, my working example is:

@JsonKey(toJson: LocationHelper.geoFirePointToJson, fromJson: LocationHelper.geoFirePointFromJson)
GeoFirePoint? geoPoint;

Here you can find my LocationHelper.


P.S.: @zeusbaba, I think you should close this issue as not relevant.

adilexperience commented 4 months ago

@emiliodallatorre LocationHelper isn't available in Flutter with this package. Can you provide its flutter code for serialization?