I have a streambuilder which stopped working today and I'm trying to debug.
Versions: firebase_core: 2.25.3 cloud_firestore: 4.15.3
It receives an object, with one of the fields being a Geopoint.
It works fine in Android and IOS, but on web it gives me an error:
Expected a value of type 'GeoPoint', but got one of type 'LegacyJavaScriptObject'
I am trying to downgrade but haven't found the issue yet.
The object:
class Branch {
final String id;
...
final GeoPoint geo;
Branch({
required this.id,
...
required this.geo,
})
factory Branch.fromFirestore(DocumentSnapshot doc) {
if (doc.exists) {
Map data = doc.data() as Map<String, dynamic>;
GeoPoint safeGeo = (data['geo'] == null)
? const GeoPoint(0.0, 0.0)
: data['geo']['geopoint'];
return Branch(
id: doc.id,
...
geo: safeGeo,
);
...
The Stream:
@riverpod
Stream<List<Branch>> myBranches(MyBranchesRef ref) {
AppUser? user = ref.watch(authStateProvider).asData?.value;
if (user is AppUser) {
var stream = ref
.watch(firestoreProvider)
.collection('branches')
.where('managers', arrayContains: user.uid)
.snapshots();
return stream.map((snapshot) =>
snapshot.docs.map((doc) => Branch.fromFirestore(doc)).toList());
} else {
return const Stream.empty();
}
}
The Screen:
return ref.watch(myBranchesProvider).when(
data: (branchList) {
...
},
error: (e, st) => ...
loading: () => ...
);
The error:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following TypeErrorImpl was thrown building StreamBuilder<QuerySnapshot<Object?>>(dirty,
dependencies: [MediaQuery], state: _StreamBuilderBaseState<QuerySnapshot<Object?>,
AsyncSnapshot<QuerySnapshot<Object?>>>#aa5da):
Expected a value of type 'GeoPoint', but got one of type 'LegacyJavaScriptObject'
The relevant error-causing widget was:
StreamBuilder<QuerySnapshot<Object?>>
StreamBuilder:file:...
This was a Cloud Firestore bug.
Solved by updating to latest version:
firebase_core: ^2.25.4
cloud_firestore: ^4.15.4