Flutter 颤振自定义导航突出显示所选页面

Flutter 颤振自定义导航突出显示所选页面,flutter,flutter-layout,Flutter,Flutter Layout,我目前正在构建一个自定义的底部栏,用于快速导航。 我使用了本文中描述的导航服务 现在我想根据用户选择的页面添加高亮显示。 我尝试将RouteAware添加到我的BottomNav小部件,以便在路由更改时更新菜单,但只有在启动我的应用程序时,我才收到任何事件 class _BottomNavState extends State<BottomNav> with RouteAware { String _selectedRoute; AppRouteObserv

我目前正在构建一个自定义的底部栏,用于快速导航。

我使用了本文中描述的导航服务

现在我想根据用户选择的页面添加高亮显示。 我尝试将RouteAware添加到我的BottomNav小部件,以便在路由更改时更新菜单,但只有在启动我的应用程序时,我才收到任何事件

class _BottomNavState extends State<BottomNav> with RouteAware {
      String _selectedRoute;
      AppRouteObserver _routeObserver;
      @override
      void initState() {
        super.initState();
        _routeObserver = AppRouteObserver();
      }

      @override
      void didChangeDependencies() {
        super.didChangeDependencies();
        _routeObserver.subscribe(this, ModalRoute.of(context));
      }

      @override
      void dispose() {
        _routeObserver.unsubscribe(this);
        super.dispose();
      }

       @override
      void didPush() {
        print('didPush');
      }
我创建NavigationService的原因是,我希望在每个页面(菜单栏/底部栏/背景)上显示一致的布局。
有没有更好的办法来解决这个问题

我通过使用ChangeNotifier扩展NavigationService解决了这个问题

现在,当用户单击按钮时,我调用setSelected函数并通知菜单项重新绘制它们自己的

setSelected(String newRoute) {
    _showLeading = !checkIsHome(newRoute);
    this._currentRoute = newRoute;
    notifyListeners();
  }

我通过使用ChangeNotifier扩展NavigationService解决了这个问题

现在,当用户单击按钮时,我调用setSelected函数并通知菜单项重新绘制它们自己的

setSelected(String newRoute) {
    _showLeading = !checkIsHome(newRoute);
    this._currentRoute = newRoute;
    notifyListeners();
  }

您是否使用任何状态管理?您可以保存选项卡的索引,并确保在导航时设置正确的索引。我正在与几个提供程序进行状态管理您尝试了我的建议,将选项卡的索引保存在整个应用程序中使用的提供程序上的变量?您是否使用任何状态管理?您可以保存选项卡的索引,并确保在导航时设置正确的索引。我正在与几个提供程序进行状态管理您是否尝试了我的建议,将选项卡的索引保存在整个应用程序使用的提供程序上?
setSelected(String newRoute) {
    _showLeading = !checkIsHome(newRoute);
    this._currentRoute = newRoute;
    notifyListeners();
  }