gpt4 book ai didi

listview - Flutter - 实现放置在屏幕底部的水平、可滚动的按钮列表

转载 作者:IT王子 更新时间:2023-10-29 06:54:34 29 4
gpt4 key购买 nike

我是 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;
}

我试图用 mainAxisAlignment: mainAxisAlignment.endListView 包装在 Column 容器中,但出现以下异常:

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.

最佳答案

只需包装您的 FlatButtonColumn 里面, 然后在 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;
}

enter image description here

关于listview - Flutter - 实现放置在屏幕底部的水平、可滚动的按钮列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53016941/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com