最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

dialog - How Flutter dynamically controls the barrierDismissible of showDialog - Stack Overflow

programmeradmin3浏览0评论

How Flutter dynamically controls the barrierDismissible of showDialog

I am developing Flutter and want to implement a dialog that can be closed by clicking on the background when it pops up by default. When clicking on the button in the dialog box, a time-consuming operation will be performed. At this time, the click background needs to be set as non closable. After the time-consuming operation is completed, the click background needs to be set as closable. However, I found that methods such as showDialog or showGeneralDialog have static barriers that cannot be dynamically controlled. How can I implement this?

bool canClose = true;
showDialog(
                context: context,
                barrierDismissible: canClose,
                builder: (buildContext) {
                  return Dialog(
                    child: Container(
                      width: 300,
                      height: 300,
                      color: Colors.red,
                      child: Column(
                        children: [
                          Container(
                            height: 150,
                            color: Colors.blue,
                            child: TextButton(
                              onPressed: () {
                                canClose = false;
                              },
                              child: Text('Prohibit clicking on background to close'),
                            ),
                          ),
                          Container(
                            height: 150,
                            color: Colors.green,
                            child: TextButton(
                              onPressed: () {
                                canClose = true;
                              },
                              child: Text('You can click on the background to close it'),
                            ),
                          )
                        ],
                      ),
                    ),
                  );
                },
              );
发布评论

评论列表(0)

  1. 暂无评论