Home > Mobile >  alert dialog above of alert dialog flutter
alert dialog above of alert dialog flutter

Time:01-23

I need to show Alert Dialog above the existing Alert Dialog, the code is when I tap on the list tile, the first alert will appear, when I tap on save on the first dialog, the sound will appear, is there any way to do this and solve the problem?

 GestureDetector(
                            onTap: () {
                              showDialog(
                                context: context,
                                builder: (context) {
                                  return AlertDialog(
                                    actions: [
                                      TextButton(
                                          onPressed: () {
                                            Navigator.pop(context);
                                          },
                                          child: const Text(
                                            "Cancel",
                                            style:
                                                TextStyle(color: Colors.orange),
                                          )),
                                      TextButton(
                                          onPressed: () {
                                            AppCubit.get(context).checkPhone2(
                                                countryCode: " 962",
                                                phone: phonecontroller.text);
                                            if (state
                                                is PostCheckPhoneLoadingState) {
                                              if (AppCubit.get(context)
                                                  .checkModel!
                                                  .status = true) {
                                                showDialog(
                                                  barrierDismissible: true,
                                                  useRootNavigator: true,
                                                  useSafeArea: true,
                                                  context: context,
                                                  builder: (context) {
                                                    return AlertDialog(
                                                      content: Text(
                                                          "the phone number is registered"),
                                                    );
                                                  },
                                                );
                                                print("Truuuuuuuuuuuuuuuuuue");
                                              }
                                            }

                                            Navigator.pop(context);
                                          },
                                          child: const Text(
                                            "Save",
                                            style:
                                                TextStyle(color: Colors.orange),
                                          )),
                                    ],
                                    title: const Text("Edit Your Phone Number"),
                                    shape: OutlineInputBorder(
                                        borderRadius:
                                            BorderRadius.circular(20)),
                                    scrollable: true,
                                    content: SizedBox(
                                      height: 40,
                                      child: TextField(
                                        decoration: InputDecoration(
                                            enabledBorder: OutlineInputBorder(
                                              borderRadius:
                                                  BorderRadius.circular(10.0),
                                              borderSide: BorderSide(
                                                color: HexColor("#dedede"),
                                              ),
                                            ),
                                            focusedBorder: OutlineInputBorder(
                                              borderRadius:
                                                  BorderRadius.circular(10.0),
                                              borderSide: BorderSide(
                                                color: HexColor("#dedede"),
                                              ),
                                            ),
                                            border: OutlineInputBorder(
                                                borderRadius:
                                                    BorderRadius.circular(10))),
                                        controller: phonecontroller,
                                      ),
                                    ),
                                    // icon: const Icon(Icons.edit),
                                  );
                                },
                              );
                            },

CodePudding user response:

You are closing dialog with pop just after showing second dialog, you need to await before closing it.

TextButton(
    onPressed: () async {
      await showDialog(
GestureDetector(
  child: Text("first dialog"),
  onTap: () async {
    await showDialog(
      context: context,
      builder: (context_d) {
        return AlertDialog(
          actions: [
            TextButton(
                onPressed: () {
                  Navigator.pop(context);
                },
                child: const Text(
                  "Cancel",
                  style: TextStyle(color: Colors.orange),
                )),
            TextButton(
                onPressed: () async {
                  await showDialog(
                    barrierDismissible: true,
                    useRootNavigator: true,
                    useSafeArea: true,
                    context: context_d,
                    builder: (context_in) {
                      return AlertDialog(
                        content:
                            Text("the phone number is registered"),
                      );
                    },
                  );
                  print("Truuuuuuuuuuuuuuuuuue");

                  Navigator.pop(context);
                },
                child: const Text(
                  "Save",
                  style: TextStyle(color: Colors.orange),
                )),
          ],
          title: const Text("Edit Your Phone Number"),
          shape: OutlineInputBorder(
              borderRadius: BorderRadius.circular(20)),
          scrollable: true,
          content: SizedBox(
            height: 40,
            child: TextField(
              decoration: InputDecoration(
                  enabledBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(10.0),
                    borderSide: BorderSide(
                        // color: HexColor("#dedede"),
                        ),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(10.0),
                    borderSide: BorderSide(
                        // color: HexColor("#dedede"),
                        ),
                  ),
                  border: OutlineInputBorder(
                      borderRadius: BorderRadius.circular(10))),
              // controller: phonecontroller,
            ),
          ),
          // icon: const Icon(Icons.edit),
        );
      },
    );
  },
)

  • Related