美文网首页
2023-08-31 flutter bottomsheet 中

2023-08-31 flutter bottomsheet 中

作者: Steven_2016 | 来源:发表于2023-08-30 18:35 被阅读0次

闲话不表,关键点,增加 padding bottom

     showModalBottomSheet(context: context,
isScrollControlled:true,  // 关键代码
builder: ((context){

          return Padding(
            padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),// 关键代码
            child: Container(
              height: 220,
              child: const Padding(
                padding: EdgeInsets.all(20),
                child: TextField(),
              ),
            ),
          );
        }));

关键点有两处
1、isScrollControlled 要设置为 true
2、需要增加padding 为 MediaQuery.of(context).viewInsets.bottom

另外
如果在项目中使用到了ScreenUtilInit,需要在初始化时,增加useInheritedMediaQuery:true

参考链接

相关文章

网友评论

      本文标题:2023-08-31 flutter bottomsheet 中

      本文链接:https://www.haomeiwen.com/subject/dedamdtx.html