show method
Displays the custom sheet using showModalBottomSheet.
This method configures the sheet based on the properties provided during instantiation, such as scrollability, padding, colors, and action buttons.
After the sheet is closed, the onClose callback is invoked with the result.
Implementation
void show(BuildContext context) {
showModalBottomSheet(
backgroundColor: Colors.transparent,
isDismissible: barrierDismissible,
barrierColor: barrierColor,
barrierLabel: barrierLabel,
isScrollControlled: true,
useSafeArea: true,
context: context,
builder: (context) {
final mediaQuery = MediaQuery.of(context);
final maxHeight = mediaQuery.size.height * 0.9;
if (scrollable) {
return DraggableScrollableSheet(
expand: expand,
initialChildSize: initialChildSize,
minChildSize: minChildSize,
maxChildSize: maxChildSize,
builder: (context, scrollController) {
return Container(
decoration: BoxDecoration(
borderRadius:
const BorderRadius.vertical(top: Radius.circular(10)),
color: backgroundColor ?? Theme.of(context).cardColor,
),
padding: sheetPadding ?? const EdgeInsets.only(bottom: 16.0),
child: Column(
children: [
if (handleColor != Colors.transparent)
_buildHandle(handleColor),
Expanded(
child: body(scrollController: scrollController),
),
],
),
);
},
);
} else {
// For non-scrollable sheet, enable scrolling only if necessary
return Container(
constraints: BoxConstraints(
maxHeight: maxHeight,
),
decoration: BoxDecoration(
borderRadius:
const BorderRadius.vertical(top: Radius.circular(10)),
color: backgroundColor ?? Theme.of(context).cardColor,
),
padding: sheetPadding ?? const EdgeInsets.only(bottom: 16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (handleColor != Colors.transparent)
_buildHandle(handleColor),
Flexible(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 30, vertical: 20),
child: body(scrollController: null),
),
),
),
if (showDefaultButtons)
_buildButtons(
context,
firstButtonColor,
secondButtonColor,
firstButtonTextColor,
secondButtonTextColor,
buttonSpacing,
confirmButtonText,
cancelButtonText,
),
],
),
);
}
},
).then((value) {
if (onClose != null) {
onClose!(value);
}
});
}