我收到此错误。我很生气。
Stream<List<TestModel>> awayStream() async* {
List<TestModel> retVal = <TestModel>[];
_categoryCollectionReferance.once().then((DataSnapshot dataSnapshot) {
print(dataSnapshot.value);
retVal.add(TestModel.fromJson(dataSnapshot.value));
return retVal;
});}
错误:[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: type '_InternalLinkedHashMap<Object?, Object?>' is not a subtype of type 'Map<String, dynamic>'
print(dataSnapshot.value); -- this perfectly working.
但是我不能添加到列表中。 这是我的型号代码;
TestModel.fromSnapshot(DataSnapshot dataSnapshot) {
awayCurrentUser = dataSnapshot.value['awayCurrentUser'] ?? 0;
awayDate = dataSnapshot.value['awayDate'] ?? 0;
awayID = dataSnapshot.value['awayID'] ?? '';
awayMaxUser = dataSnapshot.value['awayMaxUser'] ?? 0;
awayPhotoUrl = dataSnapshot.value['awayPhotoUrl'] ?? '';
awayPrice = dataSnapshot.value['awayPrice'] ?? 0;
awayTitle = dataSnapshot.value['awayTitle'] ?? '';
awayUserPrice = dataSnapshot.value['awayUserPrice'] ?? 0;
awayWinner = dataSnapshot.value['awayWinner'] ?? '';
awayWinnerName = dataSnapshot.value['awayWinnerName'] ?? '';
isEnabled = dataSnapshot.value['isEnabled'] ?? true;
isFinished = dataSnapshot.value['isFinished'] ?? false;
isStatus = dataSnapshot.value['isStatus'] ?? true;
}
答案 0 :(得分:0)
这是因为 datasnapShot 不是“Map
试试这个
dataSnapshotDecoded=json.decode(dataSnapshot.value);
retVal.add(TestModel.fromJson(dataSnapshotDecoded))