Watch
1
0
Fork
You've already forked nexus
0
forked from Nexus/nexus
nexus/lib/helpers/extensions/show_adaptive_sheet.dart
Henry-Hiles 6659f21ceb
apply SafeArea on showAdaptiveSheet
This fixes actions being cut off when using button navigation.
2026-10-19 21:18:03 -04:00

24 lines
937 B
Dart

import "package:material_ui/material_ui.dart";
import "package:nexus/helpers/extensions/is_desktop.dart";
extension ShowAdaptiveSheet on BuildContext {
/// Shows the widget from [builder] in a dialog on desktop, or a bottom sheet
/// on mobile. Use the context passed to [builder] to close it.
Future<T?> showAdaptiveSheet<T>(WidgetBuilder builder) => isDesktop
? showDialog<T>(
context: this,
builder: (context) => Dialog(
clipBehavior: .antiAlias,
child: ConstrainedBox(
constraints: const .new(maxWidth: 450, maxHeight: 600),
child: Builder(builder: builder),
),
),
)
: showModalBottomSheet<T>(
context: this,
isScrollControlled: true,
constraints: .new(maxHeight: MediaQuery.sizeOf(this).height - 80),
builder: (context) => SafeArea(child: builder(context)),
);
}