UNavigator class abstract

Navigation, dialogs, sheets, pickers and overlays from anywhere, no BuildContext needed (uses navigatorKey). UNavigator.push(ProfilePage())

Constructors

UNavigator()

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

canPop → bool
True when there is a page to go back to.
no setter
context → BuildContext
The navigator's context (for APIs that need one).
no setter
currentRouteName → String?
Name of the current route, if it has one.
no setter

Static Methods

actionSheet<T>({required List<UNavAction> actions, String? title, String? message, bool showCancel = true, String? cancelText, bool barrierDismissible = true}) → Future<T?>
List of actions in a bottom sheet with a Cancel row. UNavigator.actionSheet(actions: [UNavAction(label: "Edit", onTap: edit)])
alert({required String title, required String message, String? buttonText, IconData? icon, bool barrierDismissible = true}) → Future<void>
Simple message dialog with an OK button. UNavigator.alert(title: "Done", message: "Saved")
animatedDialog<T>(Widget child, {bool barrierDismissible = true, bool useRootNavigator = true, Color? barrierColor, URouteTransitions transition = URouteTransitions.fadeScale, Duration duration = const Duration(milliseconds: 250), Curve curve = Curves.easeOut, Alignment alignment = Alignment.center, VoidCallback? onDismiss}) → Future<T?>
Dialog with a custom enter animation and alignment.
back<T>([T? result]) → void
Closes the current page/dialog/sheet, optionally with a result. UNavigator.back(true)
backCount(int count) → void
Goes back count pages.
backToRoot() → void
Goes back to the first page.
backUntil(String routeName) → void
Goes back until the route named routeName.
bottomSheet<T>(Widget child, {bool isScrollControlled = true, bool useSafeArea = true, bool isDismissible = true, bool enableDrag = true, bool showDragHandle = false, bool useRootNavigator = true, double? elevation, Color? backgroundColor, Color? barrierColor, ShapeBorder? shape, Clip? clipBehavior, BoxConstraints? constraints, VoidCallback? onDismiss}) → Future<T?>
Modal bottom sheet that moves above the keyboard. UNavigator.bottomSheet(const FilterSheet())
colorPicker({required Color defaultColor, List<Color>? colors, String? title}) → Future<Color?>
Dialog with color swatches; returns the chosen color. await UNavigator.colorPicker(defaultColor: Colors.blue)
confirm({required String title, required String message, bool destructive = false, String? confirmText, String? cancelText, IconData? icon, bool barrierDismissible = true, bool dismissOnConfirm = true, bool dismissOnCancel = true, VoidCallback? onDismiss, VoidCallback? onCancel, VoidCallback? onConfirm}) → void
Yes/no dialog with callbacks. UNavigator.confirm(title: "Delete?", message: "Cannot be undone", destructive: true, onConfirm: delete)
confirmAsync({required String title, required String message, bool destructive = false, String? confirmText, String? cancelText, IconData? icon, bool barrierDismissible = true}) → Future<bool>
Yes/no dialog that returns true/false. if (await UNavigator.confirmAsync(title: "Logout?", message: "")) logout()
datePicker({DateTime? initialDate, DateTime? firstDate, DateTime? lastDate, String? helpText, DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar, DatePickerMode initialDatePickerMode = DatePickerMode.day}) → Future<DateTime?>
Material Gregorian date picker (use UJalaliDatePicker for Persian). await UNavigator.datePicker()
dateRangePicker({DateTimeRange<DateTime>? initialRange, DateTime? firstDate, DateTime? lastDate, String? helpText}) → Future<DateTimeRange<DateTime>?>
Material date range picker.
dialog<T>(Widget child, {bool barrierDismissible = true, bool useRootNavigator = true, Color? barrierColor, RouteSettings? settings, VoidCallback? onDismiss}) → Future<T?>
Shows any widget as a dialog; returns what it pops with. UNavigator.dialog(const AlertDialog(title: Text("Hi")))
dialogResponsive<T>({required Widget child, Widget? title, bool barrierDismissible = true, bool useRootNavigator = true, Color? barrierColor, RouteSettings? settings, VoidCallback? onDismiss, double initialChildSize = 0.5, double minChildSize = 0.25, double maxChildSize = 0.9, bool expand = false}) → Future<T?>
Bottom sheet on phones, dialog on tablets/desktop. UNavigator.dialogResponsive(child: form, title: const Text("Edit"))
dismissOverlay() → void
Removes the current overlay.
draggableSheet<T>(Widget child, {double initialChildSize = 0.5, double minChildSize = 0.25, double maxChildSize = 0.9, bool expand = false, bool snap = false, List<double>? snapSizes, bool useRootNavigator = true, bool showDragHandle = false, Color? backgroundColor, ShapeBorder? shape, VoidCallback? onDismiss}) → Future<T?>
Bottom sheet the user can drag between sizes (0-1 of screen height).
fullScreenDialog<T>(Widget page, {URouteTransitions transition = URouteTransitions.upToDown, VoidCallback? onDismiss}) → Future<T?>
Opens a page as a full-screen dialog (close button, slides from top).
inputDialog({required String title, required String hint, dynamic onSubmit(String)?, VoidCallback? onCancel, String defaultValue = "", String? submitText, String? cancelText, int lines = 4, TextInputType keyboardType = TextInputType.multiline, bool obscureText = false, String? validator(String?)?}) → Future<String?>
Dialog with a text field; returns the text or null. final String? name = await UNavigator.inputDialog(title: "Name", hint: "Your name")
maybeBack<T>([T? result]) → Future<bool>
Goes back if the page allows it (respects PopScope); true when it did.
off<T>(Widget page, {URouteTransitions transition = URouteTransitions.fade, Duration duration = const Duration(milliseconds: 300), Curve curve = Curves.easeOut, bool fullscreenDialog = false, RouteSettings? settings, Object? arguments, T? result, VoidCallback? onDismiss}) → Future<T?>
Replaces the current page (e.g. splash → home). UNavigator.off(HomePage())
offAll(Widget page, {URouteTransitions transition = URouteTransitions.fade, Duration duration = const Duration(milliseconds: 300), Curve curve = Curves.easeOut, RouteSettings? settings, Object? arguments, VoidCallback? onDismiss}) → Future<void>
Clears the stack and opens a page (e.g. after logout). UNavigator.offAll(LoginPage())
offUntil<T>(Widget page, {required String untilRouteName, URouteTransitions transition = URouteTransitions.rightToLeft, Duration duration = const Duration(milliseconds: 300), Curve curve = Curves.easeOut, RouteSettings? settings, Object? arguments}) → Future<T?>
Opens a page and removes pages until the route named untilRouteName.
push<T>(Widget page, {bool fullscreenDialog = false, bool preventDuplicates = true, bool opaque = true, bool maintainState = true, URouteTransitions transition = URouteTransitions.rightToLeft, Duration duration = const Duration(milliseconds: 300), Curve curve = Curves.easeOut, RouteSettings? settings, Object? arguments, VoidCallback? onDismiss}) → Future<T?>
Opens a page with a transition (slide by default). final bool? ok = await UNavigator.push<bool>(EditPage())
showOverlay({required Widget child, Duration duration = const Duration(seconds: 3), Duration animationDuration = const Duration(milliseconds: 250), Alignment alignment = Alignment.topCenter, EdgeInsets padding = const EdgeInsets.all(20), bool dismissOnTap = false, VoidCallback? onDismiss}) → void
Shows a widget above everything for duration (0 = until dismissOverlay). UNavigator.showOverlay(child: const Text("Saved"))
timePicker({TimeOfDay? initialTime, String? helpText, TimePickerEntryMode initialEntryMode = TimePickerEntryMode.dial}) → Future<TimeOfDay?>
Material time picker. await UNavigator.timePicker()