A complete Flutter e-commerce demo application showcasing GetIt as a dependency injection solution. This project demonstrates how to structure a real-world app using the Service Locator pattern with practical examples of authentication, cart management, checkout flow, and order tracking.
This is a learning and demonstration project that shows:
- How to use GetIt for dependency injection in a Flutter app
- Real-world service architecture with proper separation of concerns
- All 9 GetIt registration methods in practical scenarios
- Proper async initialization and dependency management
- Interactive demo screen to experiment with GetIt features
- Splash Screen - Async service initialization
- Login - User authentication with form validation
- Product Listing - Browse products with real-time cart updates
- Product Details - View individual product information
- Shopping Cart - Manage cart items
- Checkout - Process orders and generate receipts
- Order History - View past orders
- Scope Demo - Understand scoped services
- GetIt Showcase - Interactive demo of GetIt features
This app follows a feature-first architecture with clear separation between:
- Models: Data structures (
product_dm.dart,order_dm.dart) - Modules: Feature screens with their cubits (splash, login, home, cart, checkout, orders)
- Repositories: Services for data access and business logic
local_repository/: Auth, secure storageremote_repository/: API, cart, database, analytics, payment processing
- Utilities: Navigation, helpers, toast notifications
lib/main.dart- Application entry pointlib/service_locator.dart- All GetIt registrations (study this file!)lib/modules/getit_showcase/- Interactive demo screenlib/utilities/navigation/app_routes.dart- Route definitions
lib/
├── main.dart # App entry point
├── service_locator.dart # ⭐ GetIt setup - START HERE
├── models/ # Data models
├── modules/ # Feature screens + cubits
│ ├── splash/
│ ├── login/
│ ├── home/
│ ├── product_detail/
│ ├── cart/
│ ├── checkout/
│ ├── orders/
│ ├── scope_demo/
│ └── getit_showcase/ # ⭐ Interactive GetIt demo
├── repositories/ # Services & business logic
│ ├── local_repository/
│ └── remote_repository/
└── utilities/
├── navigation/
└── toast_helper.dart
- Flutter SDK (3.0+)
- Dart SDK (3.8.1+)
# 1. Get dependencies
flutter pub get
# 2. Run the app
flutter run
# 3. Or run with specific device
flutter run -d chrome # Web
flutter run -d macos # macOSLogin with any credentials:
- Username: Any non-empty string
- Password: Any string (4+ characters)
Open lib/service_locator.dart to see how all services are registered. This is the heart of the dependency injection setup.
Run the app → Home screen → "Open GetIt Showcase" button
- Interactive demo of all GetIt features
- Named instances, scopes, async init, swappable implementations
- Real-time log output
Navigate through the app to see GetIt in action:
- Splash → Async service initialization
- Login → Factory controllers
- Home → Singleton services, lazy loading
- Product Detail → FactoryParam with runtime data
- Cart → Global state management
- Checkout → Complex dependency chains
- Orders → Service dependencies
Each screen and service has inline comments explaining:
- Which GetIt registration method is used
- Why that method was chosen
- How to retrieve the dependency
Try modifying registrations in service_locator.dart:
- Change a
registerSingletontoregisterLazySingleton - Add a new service with dependencies
- Create a new factoryParam registration
This project includes comprehensive documentation:
| Document | Purpose |
|---|---|
| GETIT_DEEP_DIVE.md | Complete guide: GetIt vs Provider/BlocProvider, all methods, limitations |
By exploring this project, you'll understand:
✅ Service Locator Pattern - Global dependency access without context
✅ 9 GetIt Registration Methods - When and why to use each
✅ Dependency Management - Services depending on other services
✅ Async Initialization - Proper startup sequencing
✅ Scope Management - Temporary service lifecycles
✅ Factory vs Singleton - Instance creation patterns
✅ Named Instances - Multiple registrations of same type
✅ Runtime Parameters - Dynamic service creation
This is a teaching project designed to:
- Demonstrate GetIt in a realistic app structure
- Show best practices for dependency injection
- Provide hands-on examples of all GetIt features
- Help developers choose between GetIt, Provider, and other DI solutions