Skip to content

Commit 94a04b9

Browse files
committed
refactor(router): use ShellRoute for authentication flow
- Replace nested GoRoute with ShellRoute for better structure - Move AuthenticationBloc provider to ShellRoute for shared access - Reorganize authentication and account linking routes - Improve code readability and maintainability
1 parent f89a4d5 commit 94a04b9

File tree

1 file changed

+42
-43
lines changed

1 file changed

+42
-43
lines changed

lib/router/router.dart

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -167,59 +167,58 @@ GoRouter createRouter({
167167
GoRoute(path: '/', builder: (context, state) => const SizedBox.shrink()),
168168

169169
// --- Authentication and Account Linking Flows ---
170-
// These are top-level routes that exist outside the main app shell.
171-
GoRoute(
172-
path: Routes.authentication,
173-
name: Routes.authenticationName,
174-
builder: (BuildContext context, GoRouterState state) {
175-
// Provide the AuthenticationBloc only to this part of the tree.
176-
return BlocProvider(
177-
create: (context) => AuthenticationBloc(
178-
authenticationRepository: context.read<AuthRepository>(),
179-
),
180-
child: const AuthenticationPage(),
181-
);
182-
},
183-
routes: [
184-
GoRoute(
185-
path: Routes.requestCode,
186-
name: Routes.requestCodeName,
187-
builder: (context, state) => const RequestCodePage(),
188-
),
189-
GoRoute(
190-
path: '${Routes.verifyCode}/:email',
191-
name: Routes.verifyCodeName,
192-
builder: (context, state) {
193-
final email = state.pathParameters['email']!;
194-
return EmailCodeVerificationPage(email: email);
195-
},
196-
),
197-
],
198-
),
199-
GoRoute(
200-
path: Routes.accountLinking,
201-
name: Routes.accountLinkingName,
202-
builder: (context, state) {
170+
// These are top-level routes that exist outside the main app shell. They
171+
// use ShellRoutes to provide the AuthenticationBloc to all child routes.
172+
ShellRoute(
173+
builder: (context, state, child) {
203174
return BlocProvider(
204175
create: (context) => AuthenticationBloc(
205176
authenticationRepository: context.read<AuthRepository>(),
206177
),
207-
child: const AccountLinkingPage(),
178+
child: child,
208179
);
209180
},
210181
routes: [
211182
GoRoute(
212-
path: Routes.requestCode,
213-
name: Routes.accountLinkingRequestCodeName,
214-
builder: (context, state) => const RequestCodePage(),
183+
path: Routes.authentication,
184+
name: Routes.authenticationName,
185+
builder: (BuildContext context, GoRouterState state) =>
186+
const AuthenticationPage(),
187+
routes: [
188+
GoRoute(
189+
path: Routes.requestCode,
190+
name: Routes.requestCodeName,
191+
builder: (context, state) => const RequestCodePage(),
192+
),
193+
GoRoute(
194+
path: '${Routes.verifyCode}/:email',
195+
name: Routes.verifyCodeName,
196+
builder: (context, state) {
197+
final email = state.pathParameters['email']!;
198+
return EmailCodeVerificationPage(email: email);
199+
},
200+
),
201+
],
215202
),
216203
GoRoute(
217-
path: '${Routes.verifyCode}/:email',
218-
name: Routes.accountLinkingVerifyCodeName,
219-
builder: (context, state) {
220-
final email = state.pathParameters['email']!;
221-
return EmailCodeVerificationPage(email: email);
222-
},
204+
path: Routes.accountLinking,
205+
name: Routes.accountLinkingName,
206+
builder: (context, state) => const AccountLinkingPage(),
207+
routes: [
208+
GoRoute(
209+
path: Routes.requestCode,
210+
name: Routes.accountLinkingRequestCodeName,
211+
builder: (context, state) => const RequestCodePage(),
212+
),
213+
GoRoute(
214+
path: '${Routes.verifyCode}/:email',
215+
name: Routes.accountLinkingVerifyCodeName,
216+
builder: (context, state) {
217+
final email = state.pathParameters['email']!;
218+
return EmailCodeVerificationPage(email: email);
219+
},
220+
),
221+
],
223222
),
224223
],
225224
),

0 commit comments

Comments
 (0)