show<T> static method
- required BuildContext context,
- required Widget child,
- BoxConstraints desktopConstraints = const BoxConstraints(maxWidth: double.infinity, maxHeight: double.infinity),
- BoxConstraints modalConstraints = const BoxConstraints(maxWidth: 380),
- BoxConstraints mobileConstraints = const BoxConstraints(maxWidth: double.infinity, maxHeight: double.infinity),
- EdgeInsets mobilePadding = const EdgeInsets.fromLTRB(10, 0, 10, 16),
- EdgeInsets desktopPadding = const EdgeInsets.fromLTRB(0, 0, 0, 10),
- bool isDismissible = true,
- Color? background,
Opens a new ModalPopup wrapping the provided child
.
Implementation
static Future<T?> show<T>({
required BuildContext context,
required Widget child,
BoxConstraints desktopConstraints = const BoxConstraints(
maxWidth: double.infinity,
maxHeight: double.infinity,
),
BoxConstraints modalConstraints = const BoxConstraints(maxWidth: 380),
BoxConstraints mobileConstraints = const BoxConstraints(
maxWidth: double.infinity,
maxHeight: double.infinity,
),
EdgeInsets mobilePadding = const EdgeInsets.fromLTRB(10, 0, 10, 16),
EdgeInsets desktopPadding = const EdgeInsets.fromLTRB(0, 0, 0, 10),
bool isDismissible = true,
Color? background,
}) async {
final style = Theme.of(context).style;
if (context.isMobile) {
final NavigatorState navigator = Navigator.of(
context,
rootNavigator: true,
);
final route = ModalBottomSheetRoute<T>(
modalBarrierColor: style.barrierColor,
isScrollControlled: true,
backgroundColor: background ?? style.colors.background,
isDismissible: isDismissible,
enableDrag: isDismissible,
elevation: 0,
capturedThemes: InheritedTheme.capture(
from: context,
to: navigator.context,
),
transitionAnimationController: BottomSheet.createAnimationController(
navigator,
)..duration = const Duration(milliseconds: 350),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(14),
topRight: Radius.circular(14),
),
),
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height - 60,
),
builder: (context) {
return CustomSafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 12),
if (isDismissible) ...[
Center(
child: Container(
width: 60,
height: 3,
decoration: BoxDecoration(
color: style.colors.secondaryHighlightDarkest,
borderRadius: BorderRadius.circular(12),
),
),
),
const SizedBox(height: 12),
],
Flexible(
child: Padding(
padding: mobilePadding,
child: ConstrainedBox(
constraints: mobileConstraints,
child: child,
),
),
),
],
),
);
},
);
router.obscuring.add(route);
try {
return await Navigator.of(context, rootNavigator: true).push<T>(route);
} finally {
router.obscuring.remove(route);
}
} else {
final route = RawDialogRoute<T>(
barrierColor: style.barrierColor,
barrierDismissible: isDismissible,
pageBuilder: (_, __, ___) {
final Widget body = Center(
child: Container(
constraints: modalConstraints,
width: modalConstraints.maxWidth,
margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
padding: desktopPadding,
decoration: BoxDecoration(
color: background ?? style.colors.background,
borderRadius: style.cardRadius,
),
child: ConstrainedBox(
constraints: desktopConstraints,
child: child,
),
),
);
return CustomSafeArea(
child: Material(type: MaterialType.transparency, child: body),
);
},
barrierLabel:
MaterialLocalizations.of(context).modalBarrierDismissLabel,
transitionDuration: const Duration(milliseconds: 300),
transitionBuilder: (_, Animation<double> animation, __, Widget child) {
return FadeTransition(
opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
child: child,
);
},
);
router.obscuring.add(route);
try {
return await Navigator.of(context, rootNavigator: true).push<T>(route);
} finally {
router.obscuring.remove(route);
}
}
}