Expose the "Navigate to Same View" functionality on Get package through the NavigationService
Hi,
iam using the navigationService with Flutter Web and noticed that, even iam already on the page, i can click on the button again and will be navigated to the page again. A working solution right now is:
onTap: () => window.location.pathname == Routes.home
? {}
: navigationService.navigateTo(Routes.home),
is there already a functionality in the navigationService to check it for me? If not, i guess it would be a cool Feature.
Cheers
@Rayv1 there's not functionality like that but Get does allow you to set that functionality. I should be able to expose that for the user to set through the navigation service. When I get time I'll take a look at it.
The issue can be fixed by passing StackedService.routeObserver from the release Stacked Services #0.8.3 Getx router can't find the current route unless the observer is passed in the navigator so it can't prevent the duplicate routing. Pass StackedService.routeObserver here
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Stacked Services Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
navigatorObservers: [StackedService.routeObserver], ///<- Here
navigatorKey: StackedService.navigatorKey,
initialRoute: auto_router.Routes.homeScreenRoute,
onGenerateRoute: auto_router.Router().onGenerateRoute,
);
}
}
Refer to merge request #320 which resolves this issue