How to do looping using ListView.builder and for in flutter

3,939

Consider giving some height to the Container say some 50 or 100..that will solve your issue..

Share:
3,939
uyhaW
Author by

uyhaW

Updated on December 20, 2022

Comments

  • uyhaW
    uyhaW over 1 year

    I am trying to loop my data using for and ListView.builder, here is part of my code

    Widget listData(Data myList) {
      List<Check> tab = myList.data.listItem;
      List<Widget> list = new List<Widget>();
      for (var i = 0; i < tab.length; i++) {
        List<User> user= myList.data.listItem[i].detail;
        list.add(Container(
          child: ListView.builder(
              scrollDirection: Axis.vertical,
              itemCount: user.length,
              itemBuilder: (context, index) {
                return Text("check= $i");
              }),
        ));
      }
      return Center(child: new Column(children: list));
    }
    

    I have 6 data..but using that code I always get the first data only... the other data doesn't show up in my screen... is there something that I should do to show my all data using ListView.builder and for looping

    enter image description here

    • srikanth7785
      srikanth7785 about 4 years
      Can you attach a picture of what you achieved so far..that would make it easier to understand your problem easily..
    • uyhaW
      uyhaW about 4 years
      I have edited my question... tab.length in my code is 3 but I only get first looping and the result is in the picture inside my question
    • srikanth7785
      srikanth7785 about 4 years
      Where are you calling listData..?
    • uyhaW
      uyhaW about 4 years
      @override Widget build(BuildContext context) { return listData(); }
    • uyhaW
      uyhaW about 4 years
      I am calling listData like that.. I am calling it inside my Stateful widget
    • srikanth7785
      srikanth7785 about 4 years
      Try to give some height to the Container that you mentioned in the question..say some 50 or 100.. not sure if it works.. just give it a try..