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?
CodePudding user response:
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
CodePudding user response:
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;
},
);
}