错误状态:没有元素 AutoTabsScaffold (auto_route)

Bad state: No element AutoTabsScaffold (auto_route)

我正在使用 flutter_native_splashinjectableauto_route 依赖项。我有 3 页,概述(主页),关于和防止页面。我正在使用 AutoTabsScaffold 创建 bottomNavbar 但我一直在获取

The following StateError was thrown building AutoTabsScaffold: Bad state: No element

这是我的代码:

main.dart

void main() async {
  //*INFO:  the plugin needs to use platform channels to call the native code, which is done asynchronously therefore you have to call ensureInitialized() to make sure that you have an instance of the WidgetsBinding.
  WidgetsFlutterBinding.ensureInitialized();
  configureDependencies();
  //* INFO: flutter_native_splash
  await initialization(null);
  runApp(AppWidget());
}

Future initialization(BuildContext? context) async {
  // you can do stuff here
  await Future.delayed(const Duration(seconds: 3));
  // FlutterNativeSplash.remove();
}

app_widget.dart

class AppWidget extends StatelessWidget {
  AppWidget({Key? key}) : super(key: key);
  final _appRouter = AppRouter();

  @override
  Widget build(BuildContext context) {
    return  MaterialApp.router(
      routerDelegate: _appRouter.delegate(),
      routeInformationParser: _appRouter.defaultRouteParser(),
      title: 'Covid',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(visualDensity : VisualDensity.adaptivePlatformDensity),
      
      
    );
  }
}

router.dart

@MaterialAutoRouter(
  replaceInRouteName: 'Page,Route',
  routes: <AutoRoute>[
    AutoRoute(path: '/', page: HomePage, children: [
      AutoRoute(
          path: 'overview',
          name: 'OverviewRouter',
          page:  OverviewPage,
         
          )
    ]),
    AutoRoute(
      path: 'about',
      name: 'AboutRouter',
      page: AboutPage
    ),
    AutoRoute(
      path: 'prevent',
      name: 'PreventRouter',
      page: PreventPage
    )
  ],
)
class $AppRouter {}

home_page.dart

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AutoTabsScaffold( //TODO(Current) : Fix this! 
      routes: const [OverviewRouter(), AboutRouter(), PreventRouter()],
      appBarBuilder: (_, tabsRouter) => AppBar(
        backgroundColor: Colors.amber,
        title: const Text('Covid'),
        centerTitle: true,
        leading: const AutoBackButton(),
      ),
      bottomNavigationBuilder: (_, tabsRouter) {
        return SalomonBottomBar(
          margin: const EdgeInsets.symmetric(
            horizontal: 20,
            vertical: 40,
          ),
          currentIndex: tabsRouter.activeIndex,
          onTap: tabsRouter.setActiveIndex,
          items: [
            SalomonBottomBarItem(
              selectedColor: Colors.amberAccent,
              icon: const Icon(
                Icons.home,
                size: 30,
              ),
              title: const Text('Posts'),
            ),
            SalomonBottomBarItem(
              selectedColor: Colors.blue[200],
              icon: const Icon(
                Icons.insert_chart,
                size: 30,
              ),
              title: const Text('Users'),
            ),
            SalomonBottomBarItem(
              selectedColor: Colors.pinkAccent[100],
              icon: const Icon(
                Icons.info,
                size: 30,
              ),
              title: const Text('Settings'),
            ),
          ],
        );
      },
    );
  }

关于此错误的可能原因的任何想法。

注意:所有页面只包含一个容器小部件

当您从空列表中调用元素时,状态不佳,没有元素出现。 这意味着我的问题出在 router.dart,所有其他路由都应该是家庭路由器的子路由,意思是:

router.dart

@MaterialAutoRouter(
  replaceInRouteName: 'Page,Route',
  routes: <AutoRoute>[
    AutoRoute(path: '/', page: HomePage, children: [
      AutoRoute(path: 'overview', name: 'OverviewRouter', page: OverviewPage),
      AutoRoute(path: 'about', name: 'AboutRouter', page: AboutPage),
      AutoRoute(path: 'prevent', name: 'PreventRouter', page: PreventPage)
    ])
  ],
)
class $AppRouter {}