Complete the code to create a simple Riverpod provider that returns a string.
final greetingProvider = Provider<String>((ref) {
return [1];
});The provider must return a string. "Hello Riverpod" is a valid string.
Complete the code to read the provider value inside a ConsumerWidget build method.
Widget build(BuildContext context, WidgetRef ref) {
final greeting = ref.[1](greetingProvider);
return Text(greeting);
}read instead of watch inside build.observe.Use ref.watch to listen to provider changes and rebuild the widget.
Fix the error in the provider declaration by completing the missing keyword.
final counterProvider = [1]<int>((ref) { return 0; });
Provider when state changes are needed.FutureProvider incorrectly.Use StateProvider to create a provider that holds a mutable state like an integer counter.
Fill both blanks to update the state of a StateProvider inside a ConsumerWidget.
ref.[1](counterProvider.notifier).[2]((state) => state + 1);
watch instead of read for notifier.update.Use ref.read to get the notifier and update to change the state.
Fill all three blanks to create a FutureProvider that fetches a string asynchronously.
final dataProvider = FutureProvider<String>((ref) async {
final response = await fetchData();
return [1];
});
Future<String> fetchData() async {
await Future.delayed(Duration(seconds: 1));
return [2];
}
// Usage inside build:
final asyncValue = ref.[3](dataProvider);read instead of watch inside build.Return the awaited response, return a string in fetchData, and use watch to listen to the FutureProvider.