How to show dialog without blocking entire screen in Flutter

35 views Asked by At

I have an application with AppBar, body and footer like this:

  @override
  Widget build(BuildContext context) {
    return Scaffold(
          appBar: AppBar(
            title: Text(myWindow),
            actions: [
              PopupMenuButton(itemBuilder: (context) {
                return [
                  PopupMenuItem<int>(
                    value: 0,
                    child: Text(AppLocalizations.of(context)!.endConnection +
                        serverData.serverName),
                  ),
                ];
              }, onSelected: (value) {
                if (value == 0) {
                  clickCancel();
                }
              }),
            ],
          ),
          body:  MyPageWidget(),
          bottomNavigationBar: ... some buttons,
    );
  }

Inside the widget that is contained in the body, at some point I am displaying a dialog like this:

  void showAlert(BuildContext context) {
    if (widget.messageContent == null) {
      return;
    }
    showDialog(
      context: context,
      
      barrierDismissible: false,
      builder: (context) => AlertDialog(
        title: Text(widget.messageContent!.windowTitle),
        content: SingleChildScrollView(
          scrollDirection: Axis.vertical,
          child: ServerSessionContent(
            sendMessage: widget.sendMessage,
            activeFocusNode: widget.activeFocusNode,
            messageContent: widget.messageContent!,
          ),
        ),
        actions: <Widget>[
          ServerSessionFooter(
            messageContent: widget.messageContent!,
            sendMessage: widget.sendMessage,
            activeFocusNode: widget.activeFocusNode,
          ),
        ],
      ),
    );
  }

The issue is that when I call showAlert, the dialog blocks the entire screen, not just the body. Is there a way to show a dialog that will block only the body and will allow the user to click on the the appBar and bottomNavigationBar without closing the dialog? I need this in order to allow the user to click on the buttons there even if the actions inside the body are blocked.

0

There are 0 answers