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
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(
.......
)
)
]
)
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)),
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With