Listview 颤振-在屏幕底部实现一个水平的、可滚动的按钮列表
我是个新手。我想在屏幕底部实现一个水平的、可滚动的按钮列表(比如Instagram的效果列表)。以下代码生成按钮列表,但每个按钮的高度都会填满整个屏幕:Listview 颤振-在屏幕底部实现一个水平的、可滚动的按钮列表,listview,flutter,Listview,Flutter,我是个新手。我想在屏幕底部实现一个水平的、可滚动的按钮列表(比如Instagram的效果列表)。以下代码生成按钮列表,但每个按钮的高度都会填满整个屏幕: @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Sample App") ), body: getEffectsWidget()); } getEffectsWidget()
@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;
}
只需将您的
FlatButton
包装在列中
,然后在FlatButton
(列内)上方创建一个小部件,用Expanded
包装以覆盖所有可用空间,您的FlatButton
将放在底部
_getListData() {
List<Widget> widgets = [];
for (int i = 0; i < 100; i++) {
widgets.add(Padding(
padding: EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
Expanded(
child: Container(),
),
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;
}
\u getListData(){
列表小部件=[];
对于(int i=0;i<100;i++){
widgets.add(Padding)(
填充:所有边缘设置(10.0),
子:列(
儿童:[
扩大(
子级:容器(),
),
扁平按钮(
按下:()=>{},
颜色:颜色。橙色,
填充:所有边缘设置(10.0),
子:列(
//替换为水平图标+文本的行
子项:[图标(Icons.add),文本(“add”)],
)),
],
)));
}
返回窗口小部件;
}
_getListData() {
List<Widget> widgets = [];
for (int i = 0; i < 100; i++) {
widgets.add(Padding(
padding: EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
Expanded(
child: Container(),
),
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;
}