How do I use collection for-loops in Flutter?

后端 未结 2 1439
野性不改
野性不改 2021-01-20 02:38

I am trying to add widgets in a SliverList using a for-loop.
But I get the following error:

error: The element type \'Se

2条回答
  •  清歌不尽
    2021-01-20 03:19

    Change your build method as follows:

    @override
    Widget build(BuildContext context) {
    //insert
    List widgets = List();          
    
    for(var i=0;i<5;i++){
      widgets.add(EachBusInfoBodyWidget(Colors.green));                  
    }
    //end insert
    return Scaffold(
    

    And also change your CustomScrollView:

         child: CustomScrollView(
          slivers:
          [
            SliverList(
              delegate: SliverChildListDelegate(
               //insert
                widgets
               //end insert
              ),
            ),
          ],
        ),
    

提交回复
热议问题