1

I'm using a custom bottom navigation bar and I want to navigate between my pages, so I used the auto_route package.

After the splash screen launches, my app screen turns white and I get this error

** Launching lib/main.dart on iPhone 13 Pro Max in debug mode...
Running Xcode build...
Xcode build done.                                           64.2s
Debug service listening on ws://127.0.0.1:55355/joEDYrkJRvA=/ws
Syncing files to device iPhone 13 Pro Max...
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Can not navigate to MainPage
#0      RoutingController._findPathScopeOrReportFailure (package:auto_route/src/router/controller/routing_controller.dart:182:7)
#1      StackRouter.pushNamed (package:auto_route/src/router/controller/routing_controller.dart:1196:19)
#2      _SplashPageState.initState.<anonymous closure> (package:emart/pages/splash_page.dart:23:28)
#3      Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
#4      _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
#5      _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
#6      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12) **

This is my Route page

@MaterialAutoRouter(
  replaceInRouteName: 'Page,Router',
  routes: [
    AutoRoute(
        path: '/',
        page: SplashPage,
        initial: true,
        children: [
          // Main Page
          AutoRoute(
         path: 'auth',
            name: 'MainPageRouter',
            page: EmptyRouterPage,
          ),
          // Home Page
          AutoRoute(
            path: 'pages',
            name: 'HomeRouter',
            page: EmptyRouterPage,
            children: [
              AutoRoute(path: 'pages', page: HomePage,
              ),
            ],
          ),
          //Brands Page
          AutoRoute(
            path: 'pages',
            name: 'BrandsRouter',
            page: EmptyRouterPage,
            children: [
              AutoRoute(path: 'pages', page: BrandsPage,
              ),
            ],
          ),
          //  ProfileBody
          AutoRoute(
              path: 'profile',
              name: 'UsersRouter',
              page: EmptyRouterPage,
              children: [
                AutoRoute(
                  path: 'profile',
                  page:ProfileBody,
                ),
                AutoRoute(
                  path: 'profile',
                  page:AccountPageInfo,
                ),
                AutoRoute(
                  path: 'profile',
                  page:CridetCardPage,
                ),
              ]
          ),
        ]),
  ],
)

class $AppRouter {}

Are there any mistakes in the way that I did the routing?

and this is my splash screen

class SplashPage extends StatefulWidget {
  const SplashPage({Key? key}) : super(key: key);

  @override
  State<SplashPage> createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {

  //After 3 Seconds load login page
  Timer? _timer;
  @override
  void initState() {
    _timer = Timer(const Duration(seconds: 3),() =>

    AutoRouter.of(context).pushNamed('MainPage'),
    );
    super.initState();
  }

  @override
  void dispose() {
    _timer?.cancel();
    super.dispose();
  }


  @override
  Widget build(BuildContext context) {
    return Center(
        child: Image.asset("assets/splash.gif",
          // fit: BoxFit.fill,
        )

    );
  }
}
lepsch
  • 8,927
  • 5
  • 24
  • 44
Sally
  • 11
  • 2

0 Answers0