0

I have a conceptual question about how Flutter goes about data/state management when using go_router navigation. My app has a homepage containing a calendar that shows a list of events from a database (using the riverpod package to listen to the API calls). I also have a separate event page that shows the data of an event given its ID. The route to the event is a subroute of the home route (see route definition below).

I want to allow users to navigate immediately to this event page by way of a notification on mobile or a URL to the page (e.g. host/event/SomeEventID). However, to minimize API calls, I want to know whether this type of navigation under the hood calls the HomePage builder in any way that may trigger the API call to fetch all the events and if so, how to prevent this from happening.

Current route definition:

List<GoRoute> routes => <GoRoute>[
      GoRoute(
        name: 'home',
        path: '/',
        builder: (_, __) => const HomePage(),
        routes: <GoRoute>[
          GoRoute(
            name: 'event',
            path: 'event/:id',
            builder: (context, state) {
                // TODO: Fetch data
                // NOTE: Navigate to home if the id does not match an event
                // final String id = state.params['id']!;
            },
          ),
        ],
      ),
    ];
Ismaili Mohamedi
  • 906
  • 7
  • 15
Wessel
  • 617
  • 4
  • 13

1 Answers1

0

I have found a way to navigate directly to a subroute, and it turns out that indeed the HomePage gets build even though it is not navigated to.

Wessel
  • 617
  • 4
  • 13