I added a ripple effect to the custom build button when the user navigates to a new page. For the display ripple effect inside the button for a while, I delayed the user navigation to the new page by 150 milliseconds as in the code snippet below.
onTap: () {
Future.delayed(const Duration(milliseconds: 150), () {
context.push("/SampleNextPage");
});
},
Defining Routes
go_router 5.0.5
class Routes {
final router = GoRouter(
// initialLocation: "HomeTitlesPage",
routes: [
GoRoute(
path: "/",
builder: (context, state) => const SplashScreen(),
),
GoRoute(
path: "/HomePage",
builder: (context, state) => const HomePage(),
),
GoRoute(
path: "/SampleNextPage",
builder: (context, state) => const SampleNextPage(),
),
], observers: [
GoRouterObserver(),
]);
}
GoRouterObserver
class GoRouterObserver extends NavigatorObserver {
@override
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
print('Pushed route: ${route.str}'); //name comes back null
if (previousRoute != null) {
print('previousRoute: ${previousRoute.str}');
}
}
@override
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
print('Poped route: ${route.str}'); //name comes back null
if (previousRoute != null) {
print('previousRoute: ${previousRoute.str}');
}
}
@override
void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) {
print('Removed route: ${route.str}'); //name comes back null
if (previousRoute != null) {
print('previousRoute: ${previousRoute.str}');
}
}
@override
void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
print('Replaced newRoute: ${newRoute!.str}');
print('oldRoute: ${oldRoute!.str}'); //n//name comes back null
}
}
extension on Route<dynamic> {
String get str => 'route(${settings.name}: ${settings.arguments})';
}
In the meantime, if the user clicks the navigation button twice then the page is pushed twice to the route tree.
Accordingly, I need to preview the ripple effect and also prevent pushing the same page twice.
Is there a way to do that?