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: [
                      Container(
                        alignment: Alignment.center,
                        child: Text(
                          '更新提示',
                          style: TextStyle(
                            fontSize: 18
                          ),
                        ),
                      ),
                      Expanded(
                        child: ListView(
                          // physics: NeverScrollableScrollPhysics(),
                          shrinkWrap: true,
                          children: [
                            Padding(
                              padding: EdgeInsets.fromLTRB(20, 20, 20, 0),
                              child: Text(downloadData['newVersionText']),
                            )
                          ],
                        )
                      ),
                    ],
                  ),
                ),
              ),
              // 关键代码
              onVerticalDragUpdate: (e)=>false,
            );
          }
        );
      }
    );
  }

至此大功告成!

你可能感兴趣的:(flutter showModalBottomSheet 点击遮罩层关闭问题解决方案)