Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter listview is not visible

Tags:

flutter

 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

like image 702
Vishali Avatar asked Feb 13 '19 12:02

Vishali


3 Answers

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(
            .......
         )
      )
   ]
)
like image 91
Darlan D. Avatar answered Nov 20 '22 13:11

Darlan D.


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)),
like image 43
Jordan Davies Avatar answered Nov 20 '22 12:11

Jordan Davies


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.

like image 7
Fellipe Malta Avatar answered Nov 20 '22 11:11

Fellipe Malta