Skip to main content
InterviewHubPRO
Section Overview
Q44

Question 44 of 50

Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

88%
Flutter & Dart (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

Dependency Injection in Flutter: GetIt and injectable service locators.

senior LevelMost AskedCode ExampleDependency Injection

In Simple Words: Decoupling widget UI from API services and database repositories:

  • GetIt: A lightweight, fast Service Locator for Dart:
    dart
    final sl = GetIt.instance;
    void setupLocator() {
      sl.registerLazySingleton<AuthRepository>(() => AuthRepositoryImpl());
      sl.registerFactory<LoginBloc>(() => LoginBloc(sl()));
    }
    
  • Simplifies unit testing: replace AuthRepositoryImpl with a mock implementation in test setups without passing parameters down through 20 widget layers.