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

message_codes should explicitly support Map<String, dynamic> to better support JSON (Firebase) #833

Closed
kroikie opened this issue Oct 13, 2019 · 3 comments
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) plugin: cloud_firestore type: bug Something isn't working

Comments

@kroikie
Copy link
Collaborator

kroikie commented Oct 13, 2019

@kevmoo suggested i file an issue report here in regards to our discussion in this thread: google/json_serializable.dart#137

To summarize, Flutter's Firebase package returns documents from Firestore collections as _InternalLinkedHashMap<dynamic, dynamic>, but Flutter's recommended json package json_serializable expects json to come in as a Map<String, dynamic>. This results in the following error:

I/flutter ( 6352): type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>' where
I/flutter ( 6352):   _InternalLinkedHashMap is from dart:collection
I/flutter ( 6352):   Map is from dart:core
I/flutter ( 6352):   String is from dart:core

Here is an example of some code which will trigger this:

_firestore = Firestore.instance;

return _firestore.collection('favorites').where('user_id', isEqualTo: uid).getDocuments()
				.then((querySnap) {
					querySnap.documents.forEach((document) {
						print(document.data);

						Map<String, dynamic> json = document.data; //casts, but if you put breaklines through this its that _InternalLinkedHashMap<dynamic, dynamic> type
						Album album = new Album.fromJson(json['favorite_albums'][0]); //Throws the type exception
					});
				})
				.catchError((error) {
					print(error);
				});

Thank you!

@kroikie
Copy link
Collaborator Author

kroikie commented Oct 13, 2019

@jmrboosties

The issue at flutter/flutter#17417 has been closed and moved here. Future collaboration on this issue will be done here.

@iapicca iapicca added impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) type: enhancement New feature or request labels Oct 23, 2019
@kevmoo
Copy link
Collaborator

kevmoo commented Jan 23, 2020

FYI: this isn't just about pkg:json_serializable – Dart's JSON logic deals with Map values as Map<String, dynamic> – it's also what folks expect

@Salakar Salakar added plugin: cloud_firestore type: bug Something isn't working and removed type: enhancement New feature or request labels Apr 20, 2020
@Salakar
Copy link
Member

Salakar commented Jul 7, 2020

Hey all, as part of our on-going work for #2582, this has been resolved in our Firebase Firestore rework (#2913) - which has now been merged into master. We'll look at publishing some prereleases in the next few days. Thank you

@Salakar Salakar closed this as completed Jul 7, 2020
@firebase firebase locked and limited conversation to collaborators Aug 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) plugin: cloud_firestore type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants