我有一个像这样的递归 SplayTreeMap (自动生成)(伪代码):
SplayTreeMap map = <SplayTreeMap>{
Entry('path', 'cooltype'): <SplayTreeMap>{
Entry('subpath', 'othercooltype'): <SplayTreeMap>{
Entry('subsubpath', 'coolcooltype'): <SplayTreeMap>{},
},
Entry('othersubpath', 'othercooltype'): <SplayTreeMap>{},
},
}
类条目如下所示:
class Entry implements Comparable<Entry> {
String path;
String type = 'defaulttype';
int songs = 0;
Entry(this.path, this.type);
@override
int compareTo(Entry other) =>
this.path.toLowerCase().compareTo(other.path.toLowerCase());
@override
String toString() => 'Entry( ${this.path} )';
String get name => path.split('/').lastWhere((e) => e != '');
}
我想要做的是将 1 添加到Entry('subpath', 'othercooltype').songs
. 我试过map.update
了,但没有成功([ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type '(dynamic) => dynamic' is not a subtype of type '(SplayTreeMap<dynamic, dynamic>) => SplayTreeMap<dynamic, dynamic>' of 'update'
)。我还尝试保存它的值,删除密钥并添加更新的密钥,但它有问题(有时有效,有时无效)。
我当前的代码:
Entry entry = Entry(relativeString, type);
if (type == 'othercooltype') entry.songs++;
if (!submap.containsKey(entry)) {
submap[entry] = SplayTreeMap();
setState(() => valueChanged(value++));
} else {
// update key with songs++
}