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 →
05. State Management / Lesson 3 / 5

Riverpod

Declare providers globally, keep state in a ProviderScope, and handle async data with AsyncValue.

7 minIntermediate4 steps
counter.dart
1final counterProvider = NotifierProvider<Counter, int>(Counter.new);
2
3class Counter extends Notifier<int> {
4 @override
5 int build() => 0;
6
7 void increment() => state++;
8}
9
10final userProvider = FutureProvider<User>((ref) async {
11 final api = ref.watch(apiProvider);
12 return api.fetchUser();
13});
14
15class CounterText extends ConsumerWidget {
16 const CounterText({super.key});
17
18 @override
19 Widget build(BuildContext context, WidgetRef ref) {
20 final count = ref.watch(counterProvider);
21 final user = ref.watch(userProvider);
22 return Text(switch (user) {
23 AsyncData(:final value) => '${value.name}: $count',
24 AsyncError() => 'Could not load user',
25 _ => 'Loading...',
26 });
27 }
28}
29
30void main() => runApp(const ProviderScope(child: MyApp()));
Live simulatorRiverpod
ProviderScope · cartProvideritems: 0build ×1
Homebuild ×1
Headerref.watchbuild ×1
🛒 0
ProductListbuild ×1
Applesref.readbuild ×1
Breadref.readbuild ×1
Coffeeref.readbuild ×1
CartButtonref.watchbuild ×1
Checkout (0)

Same split with ref.watch / ref.read. The provider is a global declaration, the state lives in ProviderScope.

Step 1 / 4

Providers are declarations

A provider is a global, immutable declaration of how to create a value. The value itself lives in ProviderScope at the root of the app, so it's not a global variable and tests can override it.

You'll learn

  • Providers and ProviderScope
  • Notifier for mutable state
  • FutureProvider and AsyncValue
  • ConsumerWidget and ref.watch

Read the official docs

Riverpod docs ↗State management options ↗

Watch it built

10:30
State Management Like A Pro - Flutter RiverpodRobert Brunhage · 85K views
1:54:33
Flutter Riverpod 2 Tutorial for BeginnersRivaan Ranawat · 111K views
10:36
Learn Flutter Hooks and Maximize Your Code ReuseRobert Brunhage · 65K views
1 / 4
← → step · Space pause · R replay