flutter-go-router-example icon indicating copy to clipboard operation
flutter-go-router-example copied to clipboard

How to use it without context

Open Xoshbin opened this issue 10 months ago • 0 comments

Hi, Thank you for this great article, I really loved the way you handled routing and I implemented it in my app, The problem is I'm not sure how to use it without context in a notification service, I have tried this way below, there's no errors but the routing is not working.

class AppRouter {
  late final AppService appService;
  GoRouter get router => _goRouter;

  AppRouter(this.appService);

  late final GoRouter _goRouter = GoRouter(
    refreshListenable: appService,
    initialLocation: APPPAGE.home.toPath,
    routes: <RouteBase>[
      GoRoute(

and from the notification service I call it:

static void _navigateToeRoute(RemoteMessage event) async {

    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    AppService appService = AppService(sharedPreferences);
    AppRouter appRouter = AppRouter(appService);

    appRouter.router.goNamed(
          APPPAGE.notification.toName,
          pathParameters: <String, String>{'link': event.data['link']},
    );

As I said there's no errors, but not routing!! any help would be appreciated.

Xoshbin avatar Jul 14 '23 08:07 Xoshbin