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 40 forks source link

Unhandled Exception: type '_Map<String, dynamic>' is not a subtype of type 'GeoPoint' #35

Open Lsinkololwe opened 1 year ago

Lsinkololwe commented 1 year ago

Team i'm encountering the below error coming from the collection .dart file.

E/flutter ( 9784): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type '_Map<String, dynamic>' is not a subtype of type 'GeoPoint' E/flutter ( 9784): #0 GeoFireCollectionRef._buildQueryStream.. (package:geoflutterfire2/src/collection.dart:124:24)

The code in the library on line 124 is

final GeoPoint geoPoint = geoPointField['geopoint'];

monika-with-a-k commented 10 months ago

I'm encountering an issue with the same line of code, in collection.dart on line 124 final GeoPoint geoPoint = geoPointField['geopoint'];

However I get the error

flutter: type 'Null' is not a subtype of type 'GeoPoint'
flutter: 
#0      GeoFireCollectionRef._buildQueryStream.<anonymous closure>.<anonymous closure> (package:geoflutterfire2/src/collection.dart:124:24)
#1      MappedListIterable.elementAt (dart:_internal/iterable.dart:425:31)
#2      ListIterator.moveNext (dart:_internal/iterable.dart:354:26)
#3      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
#4      new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#5      new List.of (dart:core-patch/array_patch.dart:39:18)
#6      ListIterable.toList (dart:_internal/iterable.dart:224:7)
#7      GeoFireCollectionRef._buildQueryStream.<anonymous closure> (package:geoflutterfire2/src/collection.dart:137:24)
#8      _MapStream._handleData (dart:async/stream_pipe.dart:213:31)
#9      _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
#10     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#11     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:33<…>

It only seems to be an issue on iOS for me, same code works fine on Android. Any idea what this could be?

briteira commented 6 months ago

I'm using v2.3.15 and it's still happening.

After a long time, I discovered that the problem was the data type in the database.

I had something like this: image

And I changed it to this: image

from "map" to "geopoint".

It could be resolved by changing the line you mentioned from:

final GeoPoint geoPoint = geoPointField['geopoint'];

To:

final GeoPoint geoPoint = geoPointField['geopoint'] as GeoPoint;

I hope this can be like this in the next version.

briteira commented 6 months ago

@monika-with-a-k If you have a null field, you should change it to a "geopoint", or ignore the records where yourField is null in your database query

monika-with-a-k commented 5 months ago

It's solved now. Thanks