13
 Widget servicesListview() {
    return Container(
        decoration: new BoxDecoration(color: const Color(0xFFEAEAEA)),
        child: Column(
          children: <Widget>[
            ListView.builder(
                scrollDirection: Axis.vertical,
                itemCount: menServicesList.length,
                itemBuilder: (BuildContext context, int index) {
                  Text(menServicesList[index].name);
                }),
          ],
        ));
  }

I am implementing listview in my flutter project whenever i call this method list is not visible.The page becomes blank,help me to solve this

4 Answers 4

34

I have a same problem. The ListView.builder don't work inside a Column, this necessary use the Expanded. The Expanded widget allows you to expand and fill the space with the relative widget.

See this:

child: Column(
   children: <Widget>[
      Expanded(
         child: ListView.builder(
            .......
         )
      )
   ]
)
Sign up to request clarification or add additional context in comments.

Comments

9

Wrap your ListView inside of a Expanded or a Container widget, if you use a Container, you'll need to set a height/width.

This happens because ListView doesn't have a height/width property to edit.

EDIT

Don't forget to return your Text inside the itemBuilder property.

Comments

7

You're missing the return statement in your itemBuilder

itemBuilder: (BuildContext context, int index) {
    return Text(menServicesList[index].name);
}),

or

itemBuilder: (BuildContext context, int index) => Text(menServicesList[index].name)),

Comments

2

If you remove Column widget from the ListView, the list will definitely appear and if you want to give a decoration property to each element of a ListView.

Widget servicesListview() {
  return ListView.builder(
      scrollDirection: Axis.vertical,
      itemCount: menServicesList.length,
      itemBuilder: (BuildContext context, int index) {
        Container(
            decoration: new BoxDecoration(color: const Color(0xFFEAEAEA)),
            child: Text(menServicesList[index].name)
        );
      })
}

1 Comment

i tried the code which you updated its not working the page is still remains blank

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.