Flutter Bottom Sheet:用户与表格互动时如何更改高度

时间:2019-01-24 07:07:55

标签: dart flutter flutter-layout

在我的flutter应用程序中,我有一个底部的页面,该页面的初始高度显示为100。我想在用户与其互动时(例如,可以是500或全屏显示)增加其高度(例如手势检测或单击工作表上的按钮)

是否可以在装入纸张后更改其高度。

我的底页就像

  Widget _bottomSheetContainer(BuildContext context) {
    return Container(
        height: 100,
        decoration: BoxDecoration(
            border:
                Border(top: BorderSide(color: Theme.of(context).dividerColor))),
        child: Row(children: [
          Expanded(
            child:  Padding(
              padding: EdgeInsets.all(10.0),
              child: Text('Some text here!'),
            )
          ),
          Expanded(
            child: IconButton(
                icon: Icon(Icons.arrow_upward),
                // color: themeData.primaryColor,
                onPressed: () => _onPressed(context)
            ),
          ),
        ]));
  }

  _onPressed(BuildContext context) {
    BottomSheet w = context.widget;
    // Can we change the container height (from 100 to 500) that's part of the bottom sheet from here?

  }

1 个答案:

答案 0 :(得分:2)

您需要确保小部件为stateful widget,然后可以使用setState(() => ...)更新其实例参数,然后flutter将更新渲染的结果。

class _WidgetState extends State<Widget> {
  double height = 200.0; // starting height value

  Widget build() { 
    <...>
    Container(
        height: height,
    <...>
  }

  _onPressed(BuildContext context) {
      BottomSheet w = context.widget;
      // Can we change the container height (from 100 to 500) that's part of the bottom sheet from here?
      setState({
        height = 300.0; // new height value
      })
  }

}
相关问题