skip to Main Content

When I debug on chrome the alert dialog is not showing.

My code:

PopupMenuItem(
  value: 1,
  onTap: () {
    ShowMyDialog();
    Navigator.pop(context);
  },
  child: ListTile(
    leading: Icon(Icons.edit),
    title: Text("Edit"),
 ),
),

Future<void> ShowMyDialog() async {
  return await showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        title: Text("Update"),
        content: Container(
          child: TextField(
            controller: editingController,
          ),
        ),
        actions: [
          TextButton(
            onPressed: () {
              Navigator.pop(context);
            },
            child: Text("Cancel"),
          ),
          TextButton(
            onPressed: () {
              Navigator.pop(context);
            },
            child: Text("Update"),
          ),
        ],
      );
    },
  );
}

2

Answers


  1. Pass context to ShowMyDialog() method. like ShowMyDialog(context);

    Login or Signup to reply.
  2.   onTap: () {
        ShowMyDialog();
        Navigator.pop(context);
      },
    

    to

     onTap: () {
        ShowMyDialog();
    
      },
    

    You were popping the context as soon as the Dialog open so it wasn’t showing on that time . now try with this

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search