代码之家  ›  专栏  ›  技术社区  ›  skjagini

颤振底板:用户与板材交互时如何改变高度

  •  0
  • skjagini  · 技术社区  · 7 年前

    在我的颤振应用程序中,我有一个底部的表,显示的初始高度为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 回复  |  直到 7 年前
        1
  •  1
  •   Ski    7 年前

    您需要确保您的小部件 stateful widget ,然后可以使用 setState(() => ...) ,颤振将更新渲染结果。

    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
          })
      }
    
    }