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

Refactor AutoRoute according to new implementatiaon #31

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/presentation/core/app_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ import 'package:notes_firebase_ddd_course/presentation/sign_in/sign_in_page.dart
class AppWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final _appRouter = app_router.Router();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The router should be initialized outside the build(), otherwise, on hot restart it's gonna return an empty screen

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes definitely! Thanks for pointing that out!

return MultiBlocProvider(
providers: [
BlocProvider(
create: (context) =>
getIt<AuthBloc>()..add(const AuthEvent.authCheckRequested()),
)
],
child: MaterialApp(
child: MaterialApp.router(
routerDelegate: AutoRouterDelegate(_appRouter),
routeInformationParser: _appRouter.defaultRouteParser(),
title: 'Notes',
debugShowCheckedModeBanner: false,
builder: ExtendedNavigator.builder(router: app_router.Router()),
debugShowCheckedModeBanner: false,
theme: ThemeData.light().copyWith(
primaryColor: Colors.green[800],
accentColor: Colors.blueAccent,
Expand Down
11 changes: 5 additions & 6 deletions lib/presentation/routes/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import 'package:notes_firebase_ddd_course/presentation/notes/notes_overview/note
import 'package:notes_firebase_ddd_course/presentation/sign_in/sign_in_page.dart';
import 'package:notes_firebase_ddd_course/presentation/splash/splash_page.dart';

@MaterialAutoRouter(
generateNavigationHelperExtension: true,
@MaterialAutoRouter(
routes: <AutoRoute>[
MaterialRoute(page: SplashPage, initial: true),
MaterialRoute(page: SignInPage),
MaterialRoute(page: NotesOverviewPage),
MaterialRoute(page: NoteFormPage, fullscreenDialog: true),
AutoRoute(page: SplashPage, initial: true),
AutoRoute(page: SignInPage),
AutoRoute(page: NotesOverviewPage),
AutoRoute(page: NoteFormPage, fullscreenDialog: true),
],
)
class $Router {}
6 changes: 4 additions & 2 deletions lib/presentation/splash/splash_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ class SplashPage extends StatelessWidget {
state.map(
initial: (_) {},
authenticated: (_) =>
ExtendedNavigator.of(context).replace(Routes.notesOverviewPage),
context.router.replace(NotesOverviewPage(),
),
unauthenticated: (_) =>
ExtendedNavigator.of(context).replace(Routes.signInPage),
context.router.replace(SignInPageRoute(),
),
);
},
child: const Scaffold(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ environment:
dependencies:
flutter:
sdk: flutter
auto_route: ^0.6.9
auto_route: ^2.3.0
cloud_firestore: ^0.14.0+2
dartz: ^0.9.1
firebase_auth: ^0.18.0+1
Expand Down