Flutter Decoded.
esc

Type to search lessons, steps and concepts.

↑ ↓ move · ↵ open · esc close
Support
Language
Made with ♥ by Aman Singh · Support the projectNot affiliated with Google. Flutter and Dart are trademarks of Google LLC. Videos belong to their creators.
Course46 lessons
›01. Dart Foundations0/4
  1. Variables, Types & Null Safety
  2. Functions & Classes
  3. Futures, async/await & Streams
  4. Records, Patterns & Sealed Classes
›02. Flutter Fundamentals0/4
  1. Everything Is a Widget
  2. Stateless vs Stateful Widgets
  3. Widgets, Elements & RenderObjects
  4. Project Structure & Hot Reload
›03. Layout & UI0/6
  1. Constraints Go Down, Sizes Go Up
  2. Rows, Columns & Flex
  3. Stack, Positioned & Layering
  4. Lists, Grids & Slivers
  5. Responsive & Adaptive Design
  6. Theming with Material 3
›04. Interaction & Navigation0/4
  1. Taps, Gestures & Input
  2. Forms & Validation
  3. Navigator & Routes
  4. go_router & Deep Links
›05. State Management0/5
  1. Ephemeral vs App State
  2. InheritedWidget & Provider
  3. Riverpod
  4. The BLoC Pattern
  5. Choosing an Approach
›06. Data & Backend0/6
  1. HTTP & JSON
  2. Dio: Interceptors & Retries
  3. Saving Data Locally
  4. Firebase: Auth & Firestore
  5. Backend Options: Supabase, Appwrite & More
  6. Isolates & Heavy Work
›07. App Architecture0/3
  1. UI Layer & Data Layer
  2. Repositories & Dependency Injection
  3. Clean Architecture & Folder Structure
›08. Motion & Performance0/4
  1. Implicit Animations
  2. Explicit Animations
  3. Custom Painting
  4. Performance & DevTools
›09. Testing & Shipping0/4
  1. Unit, Widget & Integration Tests
  2. Environments & Flavors
  3. CI/CD & Releasing
  4. Flutter on the Web & Desktop
›10. Release Automation & Code Push0/6
  1. Codemagic: Your First Pipeline
  2. Codemagic: Code Signing
  3. Codemagic: Publish to the Stores
  4. Shorebird: Code Push for Flutter
  5. Shorebird: Safe Patching
  6. Shorebird in Codemagic
Progress0 / 46
Browse all videos →
07. App Architecture / Lesson 2 / 3

Repositories & Dependency Injection

Depend on abstract interfaces, inject implementations, and swap in fakes for tests.

6 minIntermediate4 steps
weather_repository.dart
1abstract class WeatherRepository {
2 Future<Weather> today(String city);
3}
4
5class ApiWeatherRepository implements WeatherRepository {
6 ApiWeatherRepository(this._client);
7 final http.Client _client;
8
9 @override
10 Future<Weather> today(String city) async {
11 final res = await _client.get(Uri.https('api.example.com', '/weather', {'q': city}));
12 return Weather.fromJson(jsonDecode(res.body) as Map<String, dynamic>);
13 }
14}
15
16class FakeWeatherRepository implements WeatherRepository {
17 @override
18 Future<Weather> today(String city) async => Weather.sunny(city);
19}
20
21// Wire the real implementation once, at the top of the app
22void main() => runApp(
23 Provider<WeatherRepository>(
24 create: (_) => ApiWeatherRepository(http.Client()),
25 child: const WeatherApp(),
26 ),
27);
Step 1 / 4

Define what, not how

An abstract class describes what the app needs: "give me today's weather for a city". Nothing about HTTP or JSON.

You'll learn

  • Abstract repository interfaces
  • Constructor injection
  • Fakes for tests and demos
  • Wiring with Provider or get_it

Read the official docs

Dependency injection (architecture case study) ↗get_it on pub.dev ↗

Watch it built

13:37
Flutter Dependency Inversion For Beginners | Complete GuideFilledStacks · 63K views
The First Step To Clean Architecture | Flutter SOLID PrinciplesRivaan Ranawat · 36K views
Creational Design Patterns in Dart & Flutter | Singleton, Abstract Factory, Builder, PrototypeRivaan Ranawat · 8.9K views
1 / 4
← → step · Space pause · R replay