gpt4 book ai didi

dart - 返回 Map 的 RawChip

转载 作者:IT王子 更新时间:2023-10-29 06:58:31 26 4
gpt4 key购买 nike

我想让 RawChip 返回 map ,即我想显示标签,但是当您单击/点击它时,将处理实际值。我们能做到吗?

通常像这样的标准 RawChip(并且有效)

final List<Widget> bannerChips = bannerBloc.bannerFilter.map<Widget>((String _text) {      
return
Padding(
padding: const EdgeInsets.all(10.0),
child: RawChip(
label: Text(_text),
selected: bannerBloc.selectedBanner == _text,
onSelected: (bool isSelected) {
setState(() {
bannerBloc.selectedBanner = isSelected ? _text : '';
});
},
));
}).toList();

现在我想返回像这样的 map

final List<Widget> bannerChips = bannerBloc.bannerFilter.map<Widget>((Map<String,dynamic> _map) {  
return
Padding(
padding: const EdgeInsets.all(10.0),
child: RawChip(
showCheckmark: false,
label: Text(_map['label']),
selected: bannerBloc.selectedBanner == _map['label'],
onSelected: (bool isSelected) {
setState(() {
bannerBloc.selectedBanner = isSelected ? _map['label'] : '';
});
},
));
}).toList();

但我无法让它工作。我收到此错误消息

type 'String' is not a subtype of type 'Map' of '_map'

我做错了什么?

当我希望它是 map 时,bannerFilter 看起来像这样

  List<Map<String, dynamic>> bannerFilter = [
{ 'label': 'All', 'value': 0 },
{ 'label': 'Shipped', 'value': 1 }
];

最佳答案

错误信息表明bannerBloc.bannerFilter不是

  List<Map<String, dynamic>> bannerFilter = [
{ 'label': 'All', 'value': 0 },
{ 'label': 'Shipped', 'value': 1 }
];

如你所料。

关于dart - 返回 Map 的 RawChip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54587683/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com