赞
踩
关于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组件 ], ) ], ), ), ); }); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。