0
votes

I am trying to have a scrollable horitzontal list in one of my App screens done but flutter, but I am getting the following error:

The argument type 'dynamic' can't be assigned to the parameter type 'String'.

Here is the code:

class CategoryListState extends State {

  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],
          ),

        ),

      ),
    );
  }
}

I appreciate any hint.

2

2 Answers

0
votes

try to do this

child: Text(
            categories[index].toString(),
          ),

or

List<String> categories = ['Checkboxes', 'DropDown', 'SwipeCards', 'SwipeCards', 'SwipeCards', 'SwipeCards',];
0
votes

Change to List<String> categories or categories[index].toString()