Flutter How Can I Show Dialog on Another Page

Issue

I want to show dialog when I press the button I want to be navigated to another page and then I want to show a dialog indicating that I have been navigated to that page.

So I try this code;

InkWell(
                          onTap: () async {
                            Navigator.pushAndRemoveUntil(
                                context,
                                MaterialPageRoute(
                                    builder: (context) => BottomBarD()),
                                (route) => false);
                            Dialog(
                              child: Container(
                                child: Column(
                                  children: [
                                    Text(
                                      "Navigated to Another Page",
                                      style: TextStyle(
                                        fontFamily: "Quando",
                                        fontWeight: FontWeight.w500,
                                        fontSize: 15,
                                      ),
                                    ),
                                    TextButton(
                                      onPressed: () async {
                                        Navigator.of(context).pop();
                                      },
                                      child: Text(
                                        "Okey",
                                        style: TextStyle(
                                          fontFamily: "Quando",
                                          fontSize: 15,
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            );
                          },
                          child: Container(
                            decoration: BoxDecoration(
                              gradient: LinearGradient(
                                  colors: [Colors.orangeAccent, Colors.red],
                                  begin: Alignment.bottomRight,
                                  end: Alignment.centerLeft),
                              borderRadius: BorderRadius.only(
                                bottomLeft: Radius.circular(112.0),
                                topLeft: Radius.circular(112.0),
                                bottomRight: Radius.circular(112.0),
                                topRight: Radius.circular(112.0),
                              ),
                            ),
                            height: MediaQuery.of(context).size.height * 0.065,
                            width: MediaQuery.of(context).size.width * 0.80,
                            margin: EdgeInsets.only(
                              top: 30.0,
                              bottom: 10.0,
                            ),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Container(
                                  child: Text(
                                    "Navigate and ShowDialog Button",
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                        color: Colors.white,
                                        fontSize: 17,
                                        fontFamily: "Quando"),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),

But when I press the okay button in the dialog, the okay button does not work and it gives a that error;

Unhandled Exception: Null check operator used on a null value

Solution

I put the Dialog in my second page BottomBarD() and I displayed it based on a conditional field every time the BottomBarD() loads.

Answered By – Rkdio

Answer Checked By – Mildred Charles (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *