Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in db.dart for Collection.streamData #11

Open
FireJuun opened this issue Jan 9, 2020 · 12 comments
Open

Error in db.dart for Collection.streamData #11

FireJuun opened this issue Jan 9, 2020 · 12 comments

Comments

@FireJuun
Copy link

FireJuun commented Jan 9, 2020

db.dart provides an excellent, abstract means to connect Firestore documents and collections to Flutter without all the boilerplate. However, I noticed a bug when working with streams in db.dart. When creating a stream collection, such as by calling:
StreamProvider<List<Example>>.value(value: Global.exampleRef.streamData())

...inside of a MultiProvider widget, you will get the following error message:

An exception was thrown by _MapStrean<QuerySnapshot, List> listened by StreamProvider<List>, but no 'catchError was provided.

Exception: type 'MappedListIterable<DocumentSnapshot, Example>' is not a subtype of type 'List'

In db.dart, Line 47 is missing a .toList() at the end:
Stream<List<T>> streamData() { return ref.snapshots().map((list) => list.documents.map((doc) => Global.models[T](doc.data) as T).toList()); }

@maliii3
Copy link

maliii3 commented Dec 1, 2020

Hey, I might have found the solution for your problem. I was facing the same problem as you did, while browsing in the depth of the StackOverflow, I found this Hope it helps after 11 months :)

@FireJuun
Copy link
Author

FireJuun commented Dec 4, 2020

Haha. Thanks. :)

Adding .toList() to the end of line 47 was the answer, by the way. I'm not sure if I had made that clear in my description of the issue. Technically, I probably should have just submitted a PR with the solution/update...

@lucygliang
Copy link

Thank you! I was running into the same issue and adding the toList() worked for me.

@jeswinjessor
Copy link

Hi, I was trying to fetch data from firestore using provider and this exception was thrown, have no idea what went wrong.

            ════════ Exception caught by provider ══════════

The following assertion was thrown:
An exception was throw by _MapStream<QuerySnapshot, List

listened by
StreamProvider, but no catchError was provided.
Exception:
type 'int' is not a subtype of type 'double'

ADDRESS CLASS
Address.fromFirestore(Map<String, dynamic> firestore)
: addressID = firestore['addressID'],
streetNumber = firestore['streetNumber'],
streetName = firestore['streetName'],
city = firestore['city'],
province = firestore['province'],
customerContact = firestore['customerContact'],
numberOfBedrooms = firestore['numberOfBedrooms'],
numberOfFamilyRooms = firestore['numberOfFamilyRooms'],
squareFeet = firestore['squareFeet'],
customerName = firestore['customerName'],
appointmentDate = DateFormat("yyyy-MM-dd").parse(firestore['appointmentDate']),
nextAppointmentDate = DateFormat("yyyy-MM-dd").parse(firestore['nextAppointmentDate']),
price = firestore['price'];

DATABASE SERVICE
Stream<List

getAddress(){
return _db.collection('addressCollection').snapshots().map((snapshot) =>
snapshot.docs.map((document) => Address.fromFirestore(document.data())).toList());
}
WIDGET CLASS
@OverRide
Widget build(BuildContext context) {
final address = Provider.of<List

(context, listen: false);
}
MAIN
providers: [
ChangeNotifierProvider(create: (context) => AddressProvider(),),
StreamProvider(create: (context) => firestoreService.getAddress()),
],

**I have used another provider in the same project for different collection and it worked fine, just the address is giving hard time

@jrheisler
Copy link

When you upgrade your firestore you'll wind up with a different set of errors with one related to the streamData. I can't figure it out.

Stream<List> streamData() {
return ref.snapshots().map((list) => list.documents.map((doc) => Global.modelsT as T) );
}

gives:
Expected a value of type 'Map<dynamic, dynamic>', but got one of type '() => Map<String, dynamic>'

@FireJuun
Copy link
Author

When you upgrade your firestore you'll wind up with a different set of errors with one related to the streamData. I can't figure it out.

Stream streamData() {
return ref.snapshots().map((list) => list.documents.map((doc) => Global.modelsT as T) );
}

gives:
Expected a value of type 'Map<dynamic, dynamic>', but got one of type '() => Map<String, dynamic>'

You need to add a () somewhere in your code. The error is that it wants a map as its return value, but it is instead receiving a function that creates a map... Hence the () before => Map...

Assuming everything worked before the upgrade, you may want to consider changing doc.data to doc.data()

@jrheisler let me know if that was your issue.

@jrheisler
Copy link

Exactly, but I changed it on the receiving end in the model to data(). Thank you!!!

@realrk95
Copy link

realrk95 commented Feb 8, 2021

I added my problem on SO. Putting the v.data() solved the error of Map subtypes, but now I get the stream returned as null. I don't understand what is going wrong here. I've printed the user id too and it shows correctly in the switchmap.

https://stackoverflow.com/questions/66092838/firestore-document-stream-of-user-data

Any help? @FireJuun @jrheisler

@LongKhoa0706
Copy link

When you upgrade your firestore you'll wind up with a different set of errors with one related to the streamData. I can't figure it out.
Stream streamData() {
return ref.snapshots().map((list) => list.documents.map((doc) => Global.modelsT as T) );
}
gives:
Expected a value of type 'Map<dynamic, dynamic>', but got one of type '() => Map<String, dynamic>'

You need to add a () somewhere in your code. The error is that it wants a map as its return value, but it is instead receiving a function that creates a map... Hence the () before => Map...

Assuming everything worked before the upgrade, you may want to consider changing doc.data to doc.data()

@jrheisler let me know if that was your issue.

it working <3!

@jrheisler
Copy link

@LongKhoa0706 that was exactly how I fixed the issue on my side.

@yussifm
Copy link

yussifm commented Sep 14, 2021

======== Exception caught by provider ==============================================================
The following assertion was thrown:
An exception was throw by _MapStream<QuerySnapshot<Map<String, dynamic>>, List> listened by

StreamProvider<List>, but no catchError was provided.

Exception:
Bad state: field does not exist within the DocumentSnapshotPlatform

====================================================================================================

@igbokwenu
Copy link

======== Exception caught by provider ============================================================== The following assertion was thrown: An exception was throw by _MapStream<QuerySnapshot<Map<String, dynamic>>, List> listened by

StreamProvider, but no catchError was provided.

Exception: Bad state: field does not exist within the DocumentSnapshotPlatform

====================================================================================================

I am having this exact error. Were you able to find a fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants