showExpressiveDialog<T> function
Future<T?>
showExpressiveDialog<T>({
- required BuildContext context,
- required WidgetBuilder builder,
- bool barrierDismissible = true,
Raises the dialog builder builds (an ExpressiveDialog, usually)
on the root navigator, centred over the scrim, fading in and out on the
default effects spring. Resolves to what the dialog closes with. A tap on
the scrim or the system back closes it unless barrierDismissible is
false; Escape closes it either way.
It rides ui_core's DesignDialogRoute: focus moves into the dialog and stays there (Tab from its last control comes round to its first), goes back to what held it as the dialog closes, and a screen reader hears a dialog.
Implementation
Future<T?> showExpressiveDialog<T>({
required BuildContext context,
required WidgetBuilder builder,
bool barrierDismissible = true,
bool useRootNavigator = true,
}) {
final navigator = Navigator.of(context, rootNavigator: useRootNavigator);
final colors = context.expressiveTheme.colors;
// Compose's dialog rides the platform window's fade; the default effects
// spring is Expressive's rendition of it (Compose names no motion key for
// a dialog). The route runs the token through ui_core's motion policy, as
// ExpressiveMotion.spring does: the same spring, and the same short fade
// under Reduce Motion.
final spring = ExpressiveMotion.of(context)
.tokenOf(ExpressiveMotionKey.defaultEffects);
final themes = InheritedTheme.capture(from: context, to: navigator.context);
return navigator.push<T>(
_ExpressiveDialogRoute<T>(
dampingRatio: spring.dampingRatio,
stiffness: spring.stiffness,
barrierColor: colors
.role(ScrimTokens.containerColor)
.withValues(alpha: ScrimTokens.containerOpacity),
barrierDismissible: barrierDismissible,
barrierLabel: Localizations.of<MaterialLocalizations>(
context,
MaterialLocalizations,
)?.modalBarrierDismissLabel,
// The fade over the whole safe area, as 0.2 had it: the dialog is drawn
// in the same layer, so its pixels are 0.2's.
builder: (context, details) => themes.wrap(
FadeTransition(
opacity: _Unit(details.animation),
child: SafeArea(
child: Padding(
padding:
MediaQuery.viewInsetsOf(context) +
const EdgeInsets.all(AlertDialogBehavior.padding),
child: Center(child: Builder(builder: builder)),
),
),
),
),
),
);
}