Why flutter auto_route navigation refreshes all beneath pages on pushing new page?

Viewed 354

I use auto_route package for web project to test Navigation 2.0. I use AutoRoureWrapper interface to wrap each page with some common PageScaffold widget, i.e.

class SomePage extends StatefulWidget implements AutoRoureWrapper {
  static const title = '/some-page';
  ...
  Widget wrappedRoute(BuildContext context) {
    return PageScaffold(
      title: title,
      body: this,
    );
  }
  ...
}
class PageScaffold ... {
}

class _PageScaffoldState ... {
  ...

  @override
  Widget build(...) {
    return FutureBuilder<User>(
      future: futureToGetSidebarItems(),
      builder: (context, snapshot) {
        if(snapshot.hasData) {
          final items = snapshot.data;
          final initialRoute = _getInitialRoute(items);
          return Row(
            children: [
              Sidebar(items: items, initialRoute: initialRoute),
              const VerticalDivider(width: 1),
              Expanded(child: widget.body),
            ],
          );
        },
      },
    );
  }
}

I have a Sidebar widget which contains list of clickable links to switch to route, using

AutoRoute.of(context).pushNamed('<route name>');

Now I have a problem when I switch to new page (set new route). Pushing new route forces refresh of all previously (pushed) created instances of PageScaffold and Sidebar widget receives incorrect data. I.e.

  1. Push Dashboard page (after authentication). [PageScaffold(body: Dashboard())] is in history. Network request for user permissions is executed.
  2. Push FirstPage page. [PageScaffold(body: Dashboard()), PageScaffold(body: FirstPage())] is in history. 2 network requests for user permissions (pear each page) are executed.
  3. Push SecondPage page. [PageScaffold(body: Dashboard()), PageScaffold(body: FirstPage()),, PageScaffold(body: SecondPage())] is in history. 3 network requests for user permissions (pear each page) are executed.
  4. And so on...

Why so? Why all pushed pages are refreshed and not only last one? Or what I do wrong?

P.S. When I use default Navigation 1.0 it looks good. Yes, all pushed pages accumulates in history but only latest on is refreshed.

0 Answers
Related