【问题标题】:Flutter change Height of DraggableScrollableSheet dynamicallyFlutter 动态改变 DraggableScrollableSheet 的高度
【发布时间】:2021-02-02 06:33:31
【问题描述】:

我想在按下某个按钮时更改 DraggableScrollableSheet 的高度。到目前为止,这就是我所拥有的

..other code up here...
  double _sheetSize=0.8;

  @override
  Widget build(BuildContext context) {  
  return DraggableScrollableSheet(
        initialChildSize: 0.29,
        minChildSize: 0.05,
        maxChildSize: _sheetSize,
        builder: (BuildContext context, _myScrollController) {
        return Container(
          padding:EdgeInsets.symmetric(horizontal: 40,vertical: 10),
          decoration: BoxDecoration(
              color: Colors.white,
              boxShadow: [
                BoxShadow(
                    color: Colors.grey.withOpacity(.8),
                    offset: Offset(3, 2),
                    blurRadius: 7)
              ]),
          child: PageView(
            physics: NeverScrollableScrollPhysics(),
            controller: _stepController,
            children: [
              NotificationListener<NextStep>(
                  child: SelectTimeWidget(myScrollController: _myScrollController),
                  onNotification: (notification) {
                    if(notification.moveToNextStep){
                      moveToNextStep();
                      setState(() {
                        _sheetSize=0.5;
                      });
                    }else{
                      moveToPreviousStep();
                    }
                    return null;
                  }
              ),
...some other code here...

在这个小部件中,我使用了一个通知监听器来触发一个我想要改变工作表高度的事件

              NotificationListener<NextStep>(
                  child: SelectTimeWidget(myScrollController: _myScrollController),
                  onNotification: (notification) {
                    if(notification.moveToNextStep){
                      moveToNextStep();
                      setState(() {
                        _sheetSize=0.5;
                      });
                    }else{
                      moveToPreviousStep();
                    }
                    return null;
                  }
              ),

纸张高度

maxChildSize: _sheetSize,

我做错了什么

【问题讨论】:

    标签: flutter widget


    【解决方案1】:

    经过一番真正的努力,我后来发现,在本文发布时,无法为 DraggableScrollableSheet Api 执行此操作,但还有另一种方法可以使用包实现此目的:sliding_up_panel

    【讨论】:

      【解决方案2】:

      Sliding Up Panel 是一个很好的小部件,尽管根据我的经验,小部件在较小的设备中横向扩展或尝试使用较小的设备时存在一些问题,并且 github 项目最近没有更新他们的问题。

      【讨论】:

        猜你喜欢
        • 2012-12-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-10
        • 2017-03-19
        • 2016-06-17
        相关资源
        最近更新 更多