CryptoSoo
CryptoSoo

Reputation: 11

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

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'),
);

Upvotes: 0

Views: 100

Answers (1)

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63549

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'),
);

Upvotes: 0

Related Questions