Flutter-实现位于屏幕底部的水平可滚动按钮列表

时间:2018-10-26 22:19:36

标签: listview flutter

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

我尝试用ListViewColumn包装在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.

1 个答案:

答案 0 :(得分:1)

只需将FlatButton包装在Column内,然后在FlatButton包裹的Expanded(位于列内)上方创建一个小部件,以覆盖所有可用空间和{{ 1}}将放置在底部。

FlatButton

enter image description here