flutter showModalBottomSheet 点击遮罩层关闭问题解决方案

效果图片
// 软件更新窗口
  void _haveNewVersion(){
    showModalBottomSheet(
      context: context,
      // 关键代码
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      builder: (BuildContext context) {
        return StatefulBuilder(
          builder:(stateContext, state) {
            return GestureDetector(
              child: Container(
                height: MediaQuery.of(context).size.height,
                alignment: Alignment.bottomCenter,
                color: Colors.transparent,
                child: Container(
                  constraints: BoxConstraints(
                    maxHeight: 250,
                    minHeight: 150
                  ),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(10),
                      topRight: Radius.circular(10)
                    )
                  ),
                  padding: EdgeInsets.only(top: 10),
                  child: Column( 
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: <Widget>[
                      Container(
                        alignment: Alignment.center,
                        child: Text(
                          '更新提示',
                          style: TextStyle(
                            fontSize: 18
                          ),
                        ),
                      ),
                      Expanded(
                        child: ListView(
                          // physics: NeverScrollableScrollPhysics(),
                          shrinkWrap: true,
                          children: <Widget>[
                            Padding(
                              padding: EdgeInsets.fromLTRB(20, 20, 20, 0),
                              child: Text(downloadData['newVersionText']),
                            )
                          ],
                        )
                      ),
                    ],
                  ),
                ),
              ),
              // 关键代码
              onVerticalDragUpdate: (e)=>false,
            );
          }
        );
      }
    );
  }

至此大功告成!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容