Flutter Map error
I want to build an App using Flutter and Firebase (Firestore version cloud_firestore: ^0.6.3).
When loading a Collection from Firestore using StreamBuilder to display it in a ListView
I get an error saying:
The following assertion was thrown building StreamBuilder(dirty, state:
I/flutter (26287): _StreamBuilderBaseState>#d5638):
I/flutter (26287): type '_InternalLinkedHashMap' is not a subtype of type 'Map'
I/flutter (26287): where
I/flutter (26287): _InternalLinkedHashMap is from dart:collection
I/flutter (26287): Map is from dart:core
I/flutter (26287): String is from dart:core
I/flutter (26287):
And I can't get my head around because even when removing the lines the use the
DocumentSnapshots it throws the error.
This is how I want to acces the filed in the Snapshots.
Creator.fromDoc(DocumentSnapshot doc) {
this.creatorId = doc['creatorId'];
this.name = doc['name'];
}
Or
Creator.fromMap(doc.data);
Creator.fromMap(Map<String, dynamic> map) {
if (map.containsKey('creatorId')) {
this.creatorId = map['creatorId'];
}
if (map.containsKey('name')) {
this.name = map['name'];
}
}
The Layout (Without the calls from above but even this throws the error).
This is partly copied from the firestore example.
return new Scaffold(
appBar: new AppBar(title: new Text('Creator')),
body: new StreamBuilder<QuerySnapshot>(
stream: CreatorRepo.getAllCreator(),
builder:
(BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) return new Text('Loading...');
return new ListView(
children: snapshot.data.documents.map<Widget>((DocumentSnapshot doc){
return new ExpansionTile(
title: new Text(doc['name']),
children: <Widget>[
new Text(doc['creatorId'])
],
);
}).toList(),
);
}));
Edit:
Dependencies:
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.6.3
firebase_messaging: ^0.2.4
cupertino_icons: ^0.1.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
flutter clean helped but resulted in another error:
Note: C:\Program Files\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core-0.2.3\android\src\main\java\io\flutter\plugins\firebase\core\FirebaseCorePlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
This error appears to have no effect on the app though.
When I started this project I checked the Firestore code and the data object inside the DocumentSnapshot was of type Map < String, dynamic > so I thought that every map inside an object would be of that type.
But to acces these sub Maps of an object you need to assume that that Map is of type Map < dynamic,dynamic >. Everytime I tried to acces a Map with
Map < String,dynamic > it would crash changing this to o acces these sub Maps of an object you need to assume that that Map is of type Map < dynamic,dynamic > stoped the crashes for now.
I believe this is because the Map returned from Firebase is not a Map<String, dynamic> but instead Map<dynamic, dynamic>.
See https://github.com/flutter/flutter/issues/17417 for a related issue.
Flutter now worked with Map<String,String>
When loading a Collection from Firestore using StreamBuilder to display it in a ListView
I get an error saying:
The following assertion was thrown building StreamBuilder(dirty, state:
I/flutter (26287): _StreamBuilderBaseState>#d5638):
I/flutter (26287): type '_InternalLinkedHashMap' is not a subtype of type 'Map'
I/flutter (26287): where
I/flutter (26287): _InternalLinkedHashMap is from dart:collection
I/flutter (26287): Map is from dart:core
I/flutter (26287): String is from dart:core
I/flutter (26287):
And I can't get my head around because even when removing the lines the use the
DocumentSnapshots it throws the error.
This is how I want to acces the filed in the Snapshots.
Creator.fromDoc(DocumentSnapshot doc) {
this.creatorId = doc['creatorId'];
this.name = doc['name'];
}
Or
Creator.fromMap(doc.data);
Creator.fromMap(Map<String, dynamic> map) {
if (map.containsKey('creatorId')) {
this.creatorId = map['creatorId'];
}
if (map.containsKey('name')) {
this.name = map['name'];
}
}
The Layout (Without the calls from above but even this throws the error).
This is partly copied from the firestore example.
return new Scaffold(
appBar: new AppBar(title: new Text('Creator')),
body: new StreamBuilder<QuerySnapshot>(
stream: CreatorRepo.getAllCreator(),
builder:
(BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) return new Text('Loading...');
return new ListView(
children: snapshot.data.documents.map<Widget>((DocumentSnapshot doc){
return new ExpansionTile(
title: new Text(doc['name']),
children: <Widget>[
new Text(doc['creatorId'])
],
);
}).toList(),
);
}));
Edit:
Dependencies:
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.6.3
firebase_messaging: ^0.2.4
cupertino_icons: ^0.1.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
flutter clean helped but resulted in another error:
Note: C:\Program Files\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core-0.2.3\android\src\main\java\io\flutter\plugins\firebase\core\FirebaseCorePlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
This error appears to have no effect on the app though.
When I started this project I checked the Firestore code and the data object inside the DocumentSnapshot was of type Map < String, dynamic > so I thought that every map inside an object would be of that type.
But to acces these sub Maps of an object you need to assume that that Map is of type Map < dynamic,dynamic >. Everytime I tried to acces a Map with
Map < String,dynamic > it would crash changing this to o acces these sub Maps of an object you need to assume that that Map is of type Map < dynamic,dynamic > stoped the crashes for now.
I believe this is because the Map returned from Firebase is not a Map<String, dynamic> but instead Map<dynamic, dynamic>.
See https://github.com/flutter/flutter/issues/17417 for a related issue.
Flutter now worked with Map<String,String>
Comments
Post a Comment