@@ -526,22 +526,19 @@ GoRouter createRouter({
526
526
name: Routes .accountName,
527
527
builder: (context, state) => const AccountPage (),
528
528
routes: [
529
- // Sub-route for settings
530
- GoRoute (
531
- path: Routes .settings, // Relative path 'settings'
532
- name: Routes .settingsName,
533
- builder: (context, state) {
534
- // Provide SettingsBloc here for SettingsPage and its children
535
- // Access AppBloc to get the current user ID
529
+ // ShellRoute for settings to provide SettingsBloc to children
530
+ ShellRoute (
531
+ builder: (BuildContext context, GoRouterState state, Widget child) {
532
+ // This builder provides SettingsBloc to all routes within this ShellRoute.
533
+ // 'child' will be SettingsPage, AppearanceSettingsPage, etc.
536
534
final appBloc = context.read <AppBloc >();
537
535
final userId = appBloc.state.user? .id;
538
536
539
- return BlocProvider (
537
+ return BlocProvider < SettingsBloc > (
540
538
create: (context) {
541
539
final settingsBloc = SettingsBloc (
542
540
userAppSettingsRepository:
543
- context
544
- .read <HtDataRepository <UserAppSettings >>(),
541
+ context.read <HtDataRepository <UserAppSettings >>(),
545
542
);
546
543
// Only load settings if a userId is available
547
544
if (userId != null ) {
@@ -550,39 +547,38 @@ GoRouter createRouter({
550
547
);
551
548
} else {
552
549
// Handle case where user is unexpectedly null.
553
- // This might involve logging or emitting an error state
554
- // directly in SettingsBloc if it's designed to handle it,
555
- // or simply not loading settings.
556
- // For now, we'll assume router redirects prevent this.
557
550
print (
558
- 'Warning : User ID is null when creating SettingsBloc. Settings will not be loaded.' ,
551
+ 'ShellRoute/SettingsBloc : User ID is null when creating SettingsBloc. Settings will not be loaded.' ,
559
552
);
560
553
}
561
554
return settingsBloc;
562
555
},
563
- child: const SettingsPage () , // Use the actual page
556
+ child: child , // child is the actual page widget (SettingsPage, AppearanceSettingsPage, etc.)
564
557
);
565
558
},
566
- // --- Settings Sub-Routes ---
567
559
routes: [
568
560
GoRoute (
569
- path: Routes .settingsAppearance, // 'appearance'
570
- name: Routes .settingsAppearanceName,
571
- builder:
572
- (context, state) => const AppearanceSettingsPage (),
573
- // SettingsBloc is inherited from parent route
574
- ),
575
- GoRoute (
576
- path: Routes .settingsFeed, // 'feed'
577
- name: Routes .settingsFeedName,
578
- builder: (context, state) => const FeedSettingsPage (),
579
- ),
580
- GoRoute (
581
- path: Routes .settingsNotifications, // 'notifications'
582
- name: Routes .settingsNotificationsName,
583
- builder:
584
- (context, state) =>
585
- const NotificationSettingsPage (),
561
+ path: Routes .settings, // Relative path 'settings' from /account
562
+ name: Routes .settingsName,
563
+ builder: (context, state) => const SettingsPage (),
564
+ // --- Settings Sub-Routes ---
565
+ routes: [
566
+ GoRoute (
567
+ path: Routes .settingsAppearance, // 'appearance' relative to /account/settings
568
+ name: Routes .settingsAppearanceName,
569
+ builder: (context, state) => const AppearanceSettingsPage (),
570
+ ),
571
+ GoRoute (
572
+ path: Routes .settingsFeed, // 'feed' relative to /account/settings
573
+ name: Routes .settingsFeedName,
574
+ builder: (context, state) => const FeedSettingsPage (),
575
+ ),
576
+ GoRoute (
577
+ path: Routes .settingsNotifications, // 'notifications' relative to /account/settings
578
+ name: Routes .settingsNotificationsName,
579
+ builder: (context, state) => const NotificationSettingsPage (),
580
+ ),
581
+ ],
586
582
),
587
583
],
588
584
),
0 commit comments