当前位置:   article > 正文

showModalBottomSheet高度自适应_showmodalbottomsheet 自适应高度

showmodalbottomsheet 自适应高度

关于showModalBottomSheet高度自适应

需求:
1.showModalBottomSheet根据内容大小高度自适应

2.超出最大高度(例如屏幕的三分之二)可以滑动

3.键盘弹出时自适应

  static showBottomPop(BuildContext context) {
    return showModalBottomSheet(
        context: context,
        isScrollControlled: true, //可滚动 解除showModalBottomSheet最大显示屏幕一半的限制
        shape: RoundedRectangleBorder(
          //圆角
          borderRadius: BorderRadius.vertical(top: Radius.circular(30.w)),
        ),
        builder: (BuildContext context) {
          return AnimatedPadding(
            //showModalBottomSheet 键盘弹出时自适应
            padding: MediaQuery.of(context).viewInsets, //边距(必要)
            duration: const Duration(milliseconds: 100), //时常 (必要)
            child: Container(
              // height: 180,
              constraints: BoxConstraints(
                minHeight: 90.w, //设置最小高度(必要)
                maxHeight: MediaQuery.of(context).size.height / 1.5, //设置最大高度(必要)
              ),
              padding: EdgeInsets.only(top: 34.w, bottom: 48.w),
              decoration: BoxDecoration(borderRadius: BorderRadius.vertical(top: Radius.circular(30.w)), color: Colors.white), //圆角
              child: ListView(
                shrinkWrap: true, //防止状态溢出 自适应大小
                children: <Widget>[
                  Column(
                    mainAxisSize: MainAxisSize.min,
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      //widget组件
                    ],
                  )
                ],
              ),
            ),
          );
        });
  }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/268693
推荐阅读
相关标签
  

闽ICP备14008679号