showFDialog<T> function
Future<T?>
showFDialog<T>({
- required BuildContext context,
- required Widget builder(),
- FDialogStyle style()?,
- String? barrierLabel,
- bool barrierDismissible = true,
- RouteSettings? routeSettings,
- AnimationController? transitionAnimationController,
- Offset? anchorPoint,
- bool useSafeArea = false,
Shows a dialog.
context
is used to look up the Navigator and FDialogStyle for the dialog. It is only used when the method is
called. Its corresponding widget can be safely removed from the tree before the sheet is closed.
useRootNavigator
ensures that the root navigator displays the sheet when true
. This is useful in the case that a
modal sheet needs to be displayed above all other content but the caller is inside another Navigator.
style
defaults to FDialogStyle from the closest FTheme ancestor.
barrierLabel
defaults to FLocalizations.barrierLabel.
Returns a Future
that resolves to the value (if any) that was passed to Navigator.pop when the modal sheet was
closed.
CLI
To generate and customize this widget's style:
dart run forui style create dialog
See:
- https://forui.dev/docs/overlay/dialog for working examples.
- showAdaptiveDialog for displaying a dialog with adaptive transitions depending on the platform.
- FDialogStyle for customizing a switch's appearance.
Implementation
Future<T?> showFDialog<T>({
required BuildContext context,
required Widget Function(BuildContext, FDialogStyle, Animation<double>) builder,
bool useRootNavigator = false,
FDialogStyle Function(FDialogStyle)? style,
String? barrierLabel,
bool barrierDismissible = true,
RouteSettings? routeSettings,
AnimationController? transitionAnimationController,
Offset? anchorPoint,
bool useSafeArea = false,
}) {
assert(debugCheckHasMediaQuery(context));
final navigator = Navigator.of(context, rootNavigator: useRootNavigator);
final localizations = FLocalizations.of(context) ?? FDefaultLocalizations();
final dialogStyle = style?.call(context.theme.dialogStyle) ?? context.theme.dialogStyle;
return navigator.push(
FDialogRoute<T>(
style: dialogStyle,
builder: (context, animation) => builder(context, dialogStyle, animation),
capturedThemes: InheritedTheme.capture(from: context, to: navigator.context),
barrierDismissible: barrierDismissible,
barrierLabel: barrierLabel ?? localizations.barrierLabel,
barrierOnTapHint: localizations.barrierOnTapHint(localizations.dialogSemanticsLabel),
settings: routeSettings,
anchorPoint: anchorPoint,
useSafeArea: useSafeArea,
),
);
}