openBottomSheet<T> static method
Future<T?>
openBottomSheet<T>({
- required BuildContext context,
- WidgetBuilder? contentBuilder,
- Widget? content,
- String title = '',
- List<
CuReDialogAction> actions = const [], - bool? hideCloseButton = false,
Implementation
static Future<T?> openBottomSheet<T>({
required BuildContext context,
WidgetBuilder? contentBuilder,
Widget? content,
String title = '',
List<CuReDialogAction> actions = const [],
bool? hideCloseButton = false,
bool useIsolatedNavigator = false, // 👈 flag per Navigator separato
}) {
assert(contentBuilder != null || content != null,
'You must provide either contentBuilder or content.');
final Widget builtContent = contentBuilder != null
? contentBuilder(context)
: (content ?? const SizedBox());
if (isIos()) {
return showCupertinoModalPopup<T>(
context: context,
builder: (context) {
return CupertinoActionSheet(
message: Stack(
children: [
if (hideCloseButton == null || !hideCloseButton)
CuReSpacing.vertical(0.5),
Padding(
padding: EdgeInsets.only(
top: hideCloseButton == null || hideCloseButton ? 5 : 30,
),
child: builtContent),
if (hideCloseButton == null || !hideCloseButton)
Positioned(
right: 0,
top: 0,
child: CuReButton(
type: CuReButtonType.text,
icon: CuReIcons.close,
onPressed: () => Navigator.of(context).pop(),
),
),
],
),
title: title != '' ? Text(title) : null,
actions: actions
.map((action) => CupertinoActionSheetAction(
child: Text(
action.label,
style: TextStyle(
fontSize: 14,
color: CuReDesign.primaryColor,
),
),
onPressed: () {
if (action.onPressed != null) action.onPressed!();
Navigator.of(context).pop();
},
))
.toList(),
);
},
);
} else {
return showModalBottomSheet<T>(
context: context,
isScrollControlled: true,
builder: (ctx) {
final child = Container(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (title != '') ...[
Text(
title,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
],
builtContent,
const SizedBox(height: 20),
if (actions.isNotEmpty) ...[
for (var action in actions)
TextButton(
onPressed: () {
if (action.onPressed != null) action.onPressed!();
Navigator.of(ctx).pop();
},
child: Text(
action.label,
style: TextStyle(
color: CuReDesign.primaryColor,
),
),
),
],
],
),
);
if (useIsolatedNavigator) {
return Navigator(
onGenerateRoute: (_) => MaterialPageRoute(
builder: (_) => child,
),
);
}
return child;
},
);
}
}