replaceTo<T, TO> method
Replaces the current route with a new page.
If safe is enabled, the replacement is skipped when
navigating to the same route.
Implementation
Future<T?> replaceTo<T, TO>(
Widget page, {
bool safe = false,
PageTransitionType? type,
}) async {
final currentRoute = ModalRoute.settingsOf(this)?.name;
final newRoute = page.runtimeType.toString();
if (safe && currentRoute == newRoute) return null;
return navigator.pushReplacement<T, TO>(
PageTransition(
type: type ?? PageTransitionType.fade,
child: page,
settings: RouteSettings(name: newRoute),
),
);
}