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

Add more pages to the app. #26

Open
paakjis opened this issue Feb 16, 2023 · 1 comment
Open

Add more pages to the app. #26

paakjis opened this issue Feb 16, 2023 · 1 comment

Comments

@paakjis
Copy link

paakjis commented Feb 16, 2023

Hi. Im new to AutoRoute, I cant figure out how to make more pages with this boilerplate.
So I made something liek this.

@AdaptiveAutoRouter(
  replaceInRouteName: 'Page,Route',
  routes: <AutoRoute>[
    //RedirectRoute(path: '*', redirectTo: '/'),
    AutoRoute(page: AppStartPage, initial: true),
    AutoRoute(
      path: '/home',
      page: HomePage,
      children: <AutoRoute>[
        AutoRoute<FieldInfoPage>(
          name: 'FieldInfoRoute',
          path: 'fieldInfo',
          page: FieldInfoPage,
        ),
      ],
    ),
    signInRouter,
    signUpRouter,
  ],
)

But the problem here is that after flutters "hot reload" it triggers the AppStartPage, and opens the HomePage again.

How do I make it so it doesn't open HomePage everytime it reloads?

@paakjis
Copy link
Author

paakjis commented Feb 16, 2023

I got it. After hours of seraching. The App Widget needs to be StatefulWidget for the hot-reload to work properly.

class App extends StatefulWidget {
  const App({super.key});

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  final _appRouter = AppRouter();

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      theme: ThemeData(
        appBarTheme: const AppBarTheme(color: Color.blue),
        colorScheme: ColorScheme.fromSwatch(accentColor: Color.blue),
        // fontFamily: 'Roboto',
      ),
      routerDelegate: AutoRouterDelegate(
        _appRouter,
        navigatorObservers: () => [AppRouteObserver()],
      ),
      routeInformationProvider: _appRouter.routeInfoProvider(),
      routeInformationParser: _appRouter.defaultRouteParser(),
      localizationsDelegates: const [
        AppLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
      ],
      useInheritedMediaQuery: true,
      supportedLocales: AppLocalizations.supportedLocales,
      builder: (BuildContext context, Widget? child) {
        final data = MediaQuery.of(context);

        return MediaQuery(
          data: data.copyWith(
            textScaleFactor: 1,
          ),
          child: child!,
        );
      },
    );
  }
}

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

1 participant