我是Flutter的新手。我想实现放置在屏幕底部的按钮的水平可滚动列表(例如,Instagram的效果列表)。以下代码产生了一个按钮列表,但是每个按钮的高度都占据了整个屏幕:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar( title: Text("Sample App") ),
body: getEffectsWidget());
}
getEffectsWidget() {
return ListView(
scrollDirection: Axis.horizontal,
children: _getListData() );
}
_getListData() {
List<Widget> widgets = [];
for (int i = 0; i < 100; i++) {
widgets.add(Padding(padding: EdgeInsets.all(10.0),
child:FlatButton(
onPressed: () => {},
color: Colors.orange,
padding: EdgeInsets.all(10.0),
child: Column( // Replace with a Row for horizontal icon + text
children: <Widget>[
Icon(Icons.add),
Text("Add")
],
)
)
)
);
}
return widgets;
}
我尝试用ListView
将Column
包装在mainAxisAlignment: mainAxisAlignment.end
容器中,但出现以下异常:
The following assertion was thrown during performResize():
I/flutter (23983): Horizontal viewport was given unbounded height.
I/flutter (23983): Viewports expand in the cross axis to fill their container and constrain their children to match
I/flutter (23983): their extent in the cross axis. In this case, a horizontal viewport was given an unlimited amount of
I/flutter (23983): vertical space in which to expand.