I want to place a menu button to left of categories.
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: kDefaultPaddin),
child: SizedBox(
height: 25,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: categories.length,
itemBuilder: (context, index) => buildCategory(index)),
),
);
}
That's categories code just after appbar. And I wanted to put menu button at the start of categories.
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: kDefaultPaddin),
child: SizedBox(
height: 25,
child: Row(
children: <Widget>[
IconButton(icon: Icon(Icons.menu), onPressed: () {}),
ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: categories.length,
itemBuilder: (context, index) => buildCategory(index))
],
)),
);
}
What is wrong with my code?
You need to wrap the ListView
with an Expanded
widget.
I added a demo using your code as an example:
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: kDefaultPaddin),
child: SizedBox(
height: 25,
child: Row(
children: <Widget>[
IconButton(icon: Icon(Icons.menu), onPressed: () {}),
// wrap with expanded widget
Expanded( // new line
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: categories.length,
itemBuilder: (context, index) => buildCategory(index)),
)
],
),
),
);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.