Home > Software engineering >  How to display a list of widgets inside a ListView.builder
How to display a list of widgets inside a ListView.builder

Time:01-24

I currently have a list(showContainerList) of widgets and I want to display the contents in a ListView.builder but I don't actually know the way around it

Below is my code

List<TodoContainer> showContainerList = [];
  addContainer() {
    showContainerList.add(
        TodoContainer(
      cardTitle: taskName.text,
    ));
  }

I tried code below but does not seem to work

ListView.builder(
              itemCount: showContainerList.length,
              itemBuilder: (context, index) {
                return Container(
                  height: 200,
                  child: const TodoContainer(),
                );
              })

CodePudding user response:

Try this:

ListView.builder(
              itemCount: showContainerList.length,
              itemBuilder: (context, index) {
                return Container(
                  height: 200,
                  child: showContainerList[index],
                );
              })

CodePudding user response:

The below code is what worked for me

Expanded(
            child: ListView.builder(
                itemCount: counter,
                itemBuilder: (BuildContext context, index) {
                  return TodoContainer(
                    cardTitle: taskName.text.toString(),
                  );
                }),
          )
  •  Tags:  
  • Related