Skip to content

Commit 4f917b8

Browse files
committed
feat(app): add navigator key to app bloc
- Add GlobalKey<NavigatorState> to AppBloc constructor - Implement navigatorKey getter for accessing NavigatorState - Update class fields and constructor parameters to include _navigatorKey
1 parent f67fa01 commit 4f917b8

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/app/bloc/app_bloc.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {
2525
required DataRepository<User> userRepository,
2626
required local_config.AppEnvironment environment,
2727
required AdService adService,
28+
required GlobalKey<NavigatorState> navigatorKey,
2829
this.demoDataMigrationService,
2930
this.demoDataInitializerService,
3031
this.initialUser,
@@ -34,6 +35,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {
3435
_userRepository = userRepository,
3536
_environment = environment,
3637
_adService = adService,
38+
_navigatorKey = navigatorKey,
3739
_logger = Logger('AppBloc'),
3840
super(
3941
AppState(
@@ -92,12 +94,20 @@ class AppBloc extends Bloc<AppEvent, AppState> {
9294
final DataRepository<User> _userRepository;
9395
final local_config.AppEnvironment _environment;
9496
final AdService _adService;
97+
final GlobalKey<NavigatorState> _navigatorKey;
9598
final Logger _logger;
9699
final DemoDataMigrationService? demoDataMigrationService;
97100
final DemoDataInitializerService? demoDataInitializerService;
98101
final User? initialUser;
99102
late final StreamSubscription<User?> _userSubscription;
100103

104+
/// Provides access to the [NavigatorState] for obtaining a [BuildContext].
105+
///
106+
/// This is useful for services that need a [BuildContext] but are not
107+
/// directly part of the widget tree (e.g., for showing dialogs or
108+
/// deriving theme data).
109+
GlobalKey<NavigatorState> get navigatorKey => _navigatorKey;
110+
101111
/// Handles user changes and loads initial settings once user is available.
102112
Future<void> _onAppUserChanged(
103113
AppUserChanged event,

0 commit comments

Comments
 (0)