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,
}) {
final style = Theme.of(context).style;
if (context.isMobile) {
return showModalBottomSheet(
context: context,
barrierColor: style.barrierColor,
isScrollControlled: true,
backgroundColor: background ?? style.colors.onPrimary,
isDismissible: isDismissible,
enableDrag: isDismissible,
elevation: 0,
transitionAnimationController: BottomSheet.createAnimationController(
Navigator.of(context),
)..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,
),
),
),
],
),
);
},
);
} else {
return showGeneralDialog(
context: context,
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.onPrimary,
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,
);
},
);
}
}