stacked icon indicating copy to clipboard operation
stacked copied to clipboard

Expose the "Navigate to Same View" functionality on Get package through the NavigationService

Open Rayv1 opened this issue 6 years ago • 2 comments

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 avatar Oct 02 '20 15:10 Rayv1

@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.

FilledStacks avatar Nov 04 '20 11:11 FilledStacks

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

hurbes avatar Apr 14 '21 06:04 hurbes