toClearAndPushWithFade function
Removes all routes from the navigation stack and pushes the specified page with a fade transition with optional arguments without requiring a BuildContext.
This function is useful for clearing the navigation stack and starting a new route with a fade transition from anywhere in the app, even outside the widget tree.
Example:
toClearAndPushWithFade(MyPage(), arguments: {'showIntro': true});
Implementation
void toClearAndPushWithFade(Widget page, {RouteSettings? settings}) {
Navigator.of(Utils.navigatorKey.currentContext!).pushAndRemoveUntil(
PageRouteBuilder(
settings: settings,
pageBuilder: (context, animation, secondaryAnimation) => page,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
return FadeTransition(opacity: animation, child: child);
},
),
(route) => false,
);
}