| j / k | Scroll down / up |
| gg | Scroll to top |
| G | Scroll to bottom |
| ⌘K / / | Open search |
| ? | Show this help |
| Esc | Close search / help |
| n / N | Next / previous section |
| h | Go to landing |
| d | Go to docs |
| : | Command mode — type section name |
Press ? or Esc to close
Core services registered once at bootstrap. Feature DI registered at bootstrap, scoped by lazy singletons and factories.
final sl = GetIt.instance;
Future<void> bootstrap() async {
WidgetsFlutterBinding.ensureInitialized();
// Singletons — one instance, shared across app
sl.registerSingleton<SharedPreferences>(await SharedPreferences.getInstance());
sl.registerSingleton<Logger>(initLogger());
sl.registerSingleton<FlutterSecureStorage>(const FlutterSecureStorage());
sl.registerSingleton<ApiClient>(ApiClient());
// Lazy singletons — created on first access
sl.registerLazySingleton(() => GlobalErrorCubit());
sl.registerLazySingleton(() => ThemeCubit(sl()));
sl.registerLazySingleton(() => LocalizationCubit(...));
sl.registerLazySingleton(() => ConnectivityCubit(Connectivity()));
// Feature DI — registered at bootstrap, lazy-loaded
registerAuthDependencies();
registerProfileDependencies();
registerHomeDependencies();
// ... all features
} void registerProfileDependencies() {
// Lazy singleton — one instance per app lifecycle
sl.registerLazySingleton(() => ProfileDataSource(sl<ApiClient>()));
sl.registerLazySingleton(() => ProfileStore(sl<ProfileDataSource>()));
// Factory — new instance each time
sl.registerFactory(() => ProfileCubit(sl<ProfileStore>()));
sl.registerFactory(() => FollowCubit(sl<FollowStore>()));
} class ProfileCubit extends Cubit<ProfileState> {
final ProfileStore _store;
ProfileCubit(this._store) : super(ProfileState.initial());
Future<void> fetchMyProfile() async {
emit(state.copyWith(userProfileResponse: state.userProfileResponse.loading));
final result = await _store.getMyProfile();
emit(state.copyWith(userProfileResponse: result));
}
} | Type | Registration | Scope |
|---|---|---|
| Core services | registerSingleton | One instance, app-wide |
| Feature stores | registerLazySingleton | One instance, created on first access |
| Feature cubits | registerFactory | New instance per BlocProvider |
| Data sources | registerLazySingleton | One instance, shared by stores |