“Why isn’t
ConsumerWidget
working?!”
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 👇