0

I want to make Bottom Sheet as a separate function but can't find anywhere how to achieve it. Everywhere Bottom Sheet is added as a function but is it possible to make Bottom Sheet as a common function so that I can reuse that some where else?

Elam
  • 413
  • 6
  • 19

2 Answers2

1

To use common showModalBottomSheet you need to pass current context like

void appModalBottomSheet(BuildContext context) {
  showModalBottomSheet(
    context: context,
    builder: (context) {
      return Text("Common bottomSheet");
    },
  );
}

More about showModalBottomSheet

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
0

Yes. You can create the common showModalBottomSheet and add the parameter as child for your view

 ///
 /// Show app modal bottomsheet
 ///
 Future<T?> showAppModalBottomSheet<T>({
   required BuildContext context,
   required Widget child,
   bool? isScrollControlled,
   ShapeBorder? shape,
   bool isDismissible = true,
 }) {
   return showModalBottomSheet<T>(
     isDismissible: isDismissible,
     context: context,
     elevation: AppConstants.modalElevation,
     barrierColor: AppColors.barrierColor,
     isScrollControlled: isScrollControlled ?? true,
     enableDrag: true,
     backgroundColor: AppColors.modalColor.ofContext(_context),
     shape: shape ?? AppConstants.modalShapeBorder,
     builder: (BuildContext context) {
       return child;
     },
   );
 }
Suganya
  • 419
  • 3
  • 11