How to find out which function called my widget in flutter?

65 Views Asked by At

Is there any way to find out which function between showDialog() and showModalBottomSheet() called my widget? I want to change its property based on which function is called.

this is my button code:

AppButton(
  onPressed: () async {
    showModalBottomSheet(
      useSafeArea: true,
      enableDrag: true,
      context: context,
      isDismissible: true,
      isScrollControlled: true,
      builder: (context) => const ModalsTeamManagement(),
    );
    await showDialog(
      context: context,
      builder: (context) {
        return const ModalsTeamManagement();
      },
    );
  },
  child: const Text('Team Management'),
);
1

There are 1 best solutions below

2
Md. Yeasin Sheikh On

From your current snippet it will show both but, you may use awai to confirm closing the dialog.

//you can place theses on state class 
bool wasDialog = false;
bool wasModalBottomSheet = false;
  
//use case
AppButton(
  onPressed: () async {
   wasModalBottomSheet =true; // it will  always show showModalBottomSheet
   await showModalBottomSheet(...);
   if (context.mounted) {
    wasDialog = true;
    await showDialog(...);
    }
  },
  child: const Text('Team Management'),
);