颤动实时数据库'InternalLinkedHashMap<Object?,Object?>'这个错误
Posted
技术标签:
【中文标题】颤动实时数据库\'InternalLinkedHashMap<Object?,Object?>\'这个错误【英文标题】:flutter realtime database 'InternalLinkedHashMap<Object?, Object?>' this error颤动实时数据库'InternalLinkedHashMap<Object?,Object?>'这个错误 【发布时间】:2021-08-19 21:04:21 【问题描述】:我收到此错误。我很生气。
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;
【问题讨论】:
【参考方案1】:这是因为 datasnapShot 不是 'Map
这样试试
dataSnapshotDecoded=json.decode(dataSnapshot.value);
retVal.add(TestModel.fromJson(dataSnapshotDecoded))
【讨论】:
我解决了这个问题。我有一个新问题。当我更改数据库上的数据时,无法更新数据列表。以上是关于颤动实时数据库'InternalLinkedHashMap<Object?,Object?>'这个错误的主要内容,如果未能解决你的问题,请参考以下文章