goTo<T> method

Future<T?> goTo<T>(
  1. Widget page, {
  2. bool safe = true,
  3. PageTransitionType? type,
})

Pushes a new page onto the navigation stack.

If safe is enabled, the navigation will be skipped when the current route name matches the destination page type.

Uses PageTransition for animated navigation.

Implementation

Future<T?> goTo<T>(
  Widget page, {
  bool safe = true,
  PageTransitionType? type,
}) async {
  final currentRoute = ModalRoute.settingsOf(this)?.name;
  final newRoute = page.runtimeType.toString();

  if (safe && currentRoute == newRoute) return null;

  return navigator.push<T>(
    PageTransition(
      type: type ?? PageTransitionType.rightToLeft,
      child: page,
      settings: RouteSettings(name: newRoute),
    ),
  );
}