flutter 未使用auto_route包中的AutoTabsScaffold关闭块

g6ll5ycj  于 2023-10-22  发布在  Flutter
关注(0)|答案(1)|浏览(119)

我使用auto_route包来实现一个选项卡栏和块,以便为页面提供状态。我的问题是,块不关闭时,导航之间的标签。第一次选择标签时,它会打开肘节,但永远不会关闭它。
下面是我的代码:
AppRouter:

@AutoRouterConfig()
class AppRouter extends _$AppRouter {
  @override
  List<AutoRoute> get routes => [
        AutoRoute(
          path: '/',
          page: AppWrapperRoute.page,
          initial: true,
          children: [
            AutoRoute(
              path: 'tab',
              page: TabBarRoute.page,
              children: [
                AutoRoute(path: 'page1', page: Page1Route.page),
                AutoRoute(path: 'page2', page: Page2Route.page),
                AutoRoute(path: 'page3', page: ProfileRoute.page),
              ],
            ),
          ],
        ),
      ];
}

TabBar:

@RoutePage(name: 'TabBarRoute')
class AutoTapBar extends StatelessWidget {
  const AutoTapBar({super.key});

  @override
  Widget build(BuildContext context) {
    return AutoTabsScaffold(
      routes: const [
        Page1Route(),
        Page2Route(),
        Page3Route(),
      ],
      bottomNavigationBuilder: (_, tabsRouter) {
        return BottomNavigationBar(
          currentIndex: tabsRouter.activeIndex,
          onTap: tabsRouter.setActiveIndex,
          items: const [
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: 'Page1',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.streetview),
              label: 'Page2',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.account_circle),
              label: 'Page3',
            ),
          ],
        );
      },
    );
  }
}

第三页:

@RoutePage(name: 'ProfileRoute')
class Page3Screen extends StatelessWidget {
  const Page3Screen({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (_) => di.getIt<Page3ScreenCubit>(),
      child: const _Page3Screen(),
    );
  }
}

我谷歌了一下,找不到答案。

qkf9rpyu

qkf9rpyu1#

在打开问题后,找到了解决方案...
你必须在你的路线中将状态设置为false:

AutoRoute(
              maintainState: false,
              path: 'profile',
              page: ProfileRoute.page,
            ),

相关问题