โWhy isnโt
ConsumerWidgetworking?!โ
Been there? So was I โ and hereโs what I learned ๐
โ The Mistake
I added this to my pubspec.yaml:
yaml
dependencies:
riverpod: ^2.0.0
It installed without error. But suddenly, ConsumerWidget wasnโt available, ref.watch() threw errors, and I couldnโt use ProviderScope.
I thought Riverpod was broken... until I realized my mistake. ๐
โ
The Fix
So, fix your pubspec.yaml like this:
dependencies:
flutter_riverpod: ^2.5.1
Then import it in your Dart files:
import 'package:flutter_riverpod/flutter_riverpod.dart';
๐ง Bonus Tip
Don't forget to wrap your app with ProviderScope in main.dart:
void main() {
runApp(ProviderScope(child: MyApp()));
}
Without this, providers wonโt work โ even with the correct package.
๐งต TL;DR
If you're using Riverpod in Flutter and ConsumerWidget or ref.watch() isn't working:
You likely added riverpod instead of flutter_riverpod
Fix your pubspec.yaml
Save yourself from unnecessary debugging ๐
๐ฌ Your Turn
Have you made this mistake before?
Got other Riverpod or Flutter setup tips?
Letโs chat in the comments ๐
Top comments (0)