【发布时间】:2021-11-13 16:07:20
【问题描述】:
我正在尝试将 Map
Unhandled Exception: type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, int>?' in type cast
代码:
数据控制器
Box<Map<String, int>> hiveBox = Hive.box('SaveBetBox');
void betStorage({String? matchKey, String? statKey, int? statIndex}) {
// Checks if the hive box has the data with following key if not adds
hiveBox.containsKey(matchKey)
? null
: hiveBox.put(
matchKey,
Map<String, int>(),
);
// Extract hive map to update or add Key values to Map with specific Key
Map<String, int>? tm = hiveBox.get(matchKey);
if (tm![statKey!] == null) {
tm[statKey] = statIndex!;
hiveBox.put(matchKey, tm);
} else {
tm.update(statKey, (value) => statIndex!);
}
Map<String, int>? dd = hiveBox.get(matchKey);
print('This is $statKey ${dd![statKey]}');
}
// Retrieve FN
void onitintHive() {
//Storing value i.e Map() of specific key in var
Map<String, int>? _dd = hiveBox.get("RVB");
// Extracting values from the map
int? goal1 = _dd!['t1goalkey'];
int? yc = _dd['t1yckey'];
print('This is dd : ${_dd!['t1goalkey']}');
print('This is T1 Goal : $goal1');
print('This is T1 YC : $yc');
}
main() 中的主框
await Hive.openBox<Map<String, int>>('SaveBetBox');
【问题讨论】:
-
编辑框
-
解决不了问题。还是同样的错误。 @CyrustheGreat
标签: flutter dart flutter-hive