我正在尝试通过添加具有不同子类型的Map条目将Map条目添加到现有Map中。但是我不知道该怎么办。目前,我遇到此错误。
type '_InternalLinkedHashMap<dynamic, _Tag>' is not a subtype of type 'Map<int, String>' of 'other'
class AppController{
Map<dynamic,_Tag> _list = new Map<dynamic,_Tag>();
Map<dynamic,_Tag> getList(){return _list;}
void addList(Map<dynamic,String> val){
this._list?.addAll(val.map((index, value)=>MapEntry(index, _Tag(index: index, value: value))));
}
void setSelected(Map<dynamic,String> val){
this._list?.addAll(val.map((index, value)=>MapEntry(index, _Tag(index: index, value: value, selected: true))));
}
}
class _Tag{
bool selected = false;
final dynamic index;
final String value;
_Tag({this.index, this.value, this.selected});
}
我这样称呼
TagsWidget({this.title,this.controller, Map<dynamic,String> list , Map<dynamic,String> selected}){
this.controller.addList(list);
this.controller.setSelected(selected);
}
AppController tagsCtrl = new AppController();
Map<int, String> options = {
1:'Option 1',
2:'Option 2',
3:'Option 3',
4:'Option 4',
5:'Option 5'
};
TagsWidget(
title: 'Title herer',
list: this.options ,
selected: this.options ,
controller: tagsCtrl ,
)