我试图在我的一个应用程序屏幕中完成一个可滚动的水平列表,但出现抖动,但出现以下错误:
不能将参数类型“ dynamic”分配给参数类型“ String”。
代码如下:
类别CategoryListState扩展了状态{
int selectedIndex = 0;
List categories = ['Checkboxes', 'DropDown', 'SwipeCards', 'SwipeCards', 'SwipeCards', 'SwipeCards',];
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(vertical: 20.0/2),
height: 30.0,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: categories.length,
itemBuilder: (context, index) => Container (
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 20.0),
padding: EdgeInsets.symmetric(horizontal: 20.0),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.4),
borderRadius: BorderRadius.circular(6),
),
child: Text(
categories[index],
),
),
),
);
}
}
我很感谢。
答案 0 :(得分:0)
更改为List<String> categories
或categories[index].toString()
答案 1 :(得分:0)
尝试这样做
child: Text(
categories[index].toString(),
),
或
List<String> categories = ['Checkboxes', 'DropDown', 'SwipeCards', 'SwipeCards', 'SwipeCards', 'SwipeCards',];