jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.35k stars 1.63k forks source link

Get.generalDialog() does not work inside PopupMenuButton>PopupMenuItem #2735

Open hosseinvejdani opened 1 year ago

hosseinvejdani commented 1 year ago

Describe the bug Get.generalDialog() does not work inside PopupMenuButton. when i try to lunch a generalDialog using onTap property of PopupMenuItem inside PopupMenuButton on AppBar, nothing happens.

Reproduction code

example:

PopupMenuButton(
    itemBuilder: (context) {
      return [
        PopupMenuItem(
          onTap: () => showOnDeletePlaceDialog(),
          child: Row(
            children: [
              Icon(
                Icons.delete_outline,
                size: 35.r,
                color: Theme.of(context).colorScheme.primary,
              ),
              SizedBox(width: 15.w),
              Text(
                'حذف مکان',
                style: Theme.of(context).textTheme.bodySmall?.copyWith(
                      color: Theme.of(context).colorScheme.onBackground,
                    ),
              ),
            ],
          ),
        ),
      ];
    },
  );

void showOnDeletePlaceDialog() {
  Get.back();
  Get.put(DeletePlaceDialogController());
  Get.generalDialog(
    pageBuilder: (context, animation, secondaryAnimation) {
      return AlertDialog(
        backgroundColor: Get.theme.colorScheme.background.lighten(),
        title: _title(context),
        content: _content(context),
      );
    },
  );
}

Tis message appears when i tap item:

[GETX] OPEN DIALOG 751239174
[GETX] CLOSE DIALOG 751239174

Expected behavior I expected that i see an AlertDialog

Flutter Version: Flutter 3.7.5 • channel stable

Getx Version: get: ^4.6.5

Describe on which device you found the bug: Android.

hosseinvejdani commented 1 year ago

But it works fine with opTap property of ListTile inside a PopupMenuItem:

PopupMenuItem(
  child: ListTile(
    onTap: () => showOnDeletePlaceDialog(),
    trailing: Icon(
      Icons.delete_outline,
      size: 35.r,
      color: Theme.of(context).colorScheme.primary,
    ),
    title: Text(
      'حذف مکان',
      style: Theme.of(context).textTheme.bodySmall?.copyWith(
            color: Theme.of(context).colorScheme.onBackground,
          ),
    ),
  ),
),
punit1111 commented 1 year ago

@hosseinvejdani Open dialog from onSelected method given inside PopupMenuButton instead of onTap. also remove Get.back(); from showOnDeletePlaceDialog


PopupMenuButton(
    onSelected: (int value) {
      if (value == 1) {
            showOnDeletePlaceDialog();
         }
    },
    itemBuilder: (context) {
      return [
        PopupMenuItem(
          value: 1,
          child: Row(
            children: [
              Icon(
                Icons.delete_outline,
                size: 35.r,
                color: Theme.of(context).colorScheme.primary,
              ),
              SizedBox(width: 15.w),
              Text(
                'حذف مکان',
                style: Theme.of(context).textTheme.bodySmall?.copyWith(
                      color: Theme.of(context).colorScheme.onBackground,
                    ),
              ),
            ],
          ),
        ),
      ];
    },
  );

void showOnDeletePlaceDialog() {
  Get.put(DeletePlaceDialogController());
  Get.generalDialog(
    pageBuilder: (context, animation, secondaryAnimation) {
      return AlertDialog(
        backgroundColor: Get.theme.colorScheme.background.lighten(),
        title: _title(context),
        content: _content(context),
      );
    },
  );
}