Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route back to initial splash page every time I save. #1829

Closed
BrillianceOsprey opened this issue Jan 6, 2024 · 3 comments
Closed

Route back to initial splash page every time I save. #1829

BrillianceOsprey opened this issue Jan 6, 2024 · 3 comments

Comments

@BrillianceOsprey
Copy link

  1. Here is my app_router.dart

@AutoRouterConfig()
class AppRouter extends $AppRouter {
@OverRide
List get routes => [
AutoRoute(page: SplashRoute.page, initial: true),
AutoRoute(
page: WrapperRoute.page,
path: '/start',
children: [
AutoRoute(page: HomeRoute.page, path: 'home'),

        // Settings
        AutoRoute(page: SettingRoute.page, path: 'settings'),
        AutoRoute(page: PostRoute.page, path: 'post'),
      ],
    ),
    AutoRoute(page: SigninRoute.page, path: '/signin'),
    AutoRoute(page: SignupRoute.page, path: '/signup'),
    AutoRoute(page: OnBoardingRoute.page, path: '/onboarding'),
  ];

}

  1. Here is my Material.router
    return MaterialApp.router(
    title: 'Libra',
    debugShowCheckedModeBanner: false,
    themeMode: ThemeMode.light,
    routerConfig: appRouter.config(),
    );

  2. Here is my splash page
    import 'package:auto_route/auto_route.dart';
    import 'package:flutter/material.dart';

@RoutePage()
class SplashPage extends StatefulWidget {
const SplashPage({super.key});

@OverRide
State createState() => _SplashPageState();
}

class _SplashPageState extends State {

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: const Center(
child: Text('Splash Page'),
),
);
}
}

@BrillianceOsprey
Copy link
Author

I got it , I need to declare appRoute under build method of app widget page or material.router page

@Milad-Akarie
Copy link
Owner

@BrillianceOsprey avoid declaring it in any build method, you could declare it as a final field inside of your material App

@BrillianceOsprey
Copy link
Author

BrillianceOsprey commented Jan 14, 2024

@BrillianceOsprey avoid declaring it in any build method, you could declare it as a final field inside of your material App

@Milad-Akarie Thanks for the tip! Declaring it as a final field inside the Material App sounds like a cleaner approach. Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants