admin管理员组

文章数量:1123508

I have a GUI which uses BottomNavigationBar, Drawer and go_router with a similar routing table:

GoRouter(
  routes: [
    GoRoute(
      path: '/login',
    ),
    GoRoute(
      path: '/settings',
      routes: [
        GoRoute(
          path: 'navigation',
        ),
      ],
    ),
    ShellRoute(
      routes: [
        GoRoute(
          path: '/dashboard',
        ),
        GoRoute(
          path: '/alers',
        ),
        GoRoute(
          path: '/users',
        ),
        pageBuilder: (...) {
          return ScaffoldWithNavigationShell(child: child),
        },
      ]
    ),
  ],
)

The similar GUI widget:

class _ScaffoldWithNavigationShellState extends State<...> {
  Widget build(...) {
    final navigationItems = _getDynamicallyGeneratedItems();
    return Scaffold(
      body: widget.navigationShell,
      bottomNavigation: BottomNavigationBar(
        items: navigationItems,
        onTap: _changeDestination,
      ),
    );
  }
}

void _changeDestination(int index) {
  final navigationItems = _getDynamicallyGeneratedItems();
  final currentNavigationItem = navigationItems[index];
  // go to specific route, e.g. /users
  context.go(currentNavigationItem.path); 
}

The navigationItems are built dynamically on the screen with a route /settings/navigation where user can change the sequence of naviation items, add new ones or remove them.

Let's say the user goes on /users route. To access the navigation screen the user calls a Drawer where he than pushes to route /settings, and then pushes to the route /settings/navigation. Let's say the user removed the users item from available navigation items.

The sequence of user actions:

  1. User click on users item, context.go('/users').
  2. User opens the Drawer.
  3. User clicks on Settings, context.push('/settings').
  4. User clicks on Navigation, context.push('/settings/navigation').
  5. User removes users item.
  6. User clicks back to return to Settings screen from Navigation.
  7. User closes the Drawer.

The new selected item must be alerts with alerts content.

As I use ChangeNotifier for management of navigation items with InheritedNotifierwidget the changes are reflected on the screen with BottomNavigationBar, i.e. the removed navigation item is disappeared but the content of widget linked to that route is still visible. So I see the selected item alerts but the body of Scaffold is still users related.

How to refresh (replace?) the top route with all history of pushed routes?

本文标签: