Google Flutter Google Flutter State Management 2 — Questions and Answers
Question 1: Which Riverpod provider should you use to expose a simple immutable value?
- StateProvider
- Provider (Correct answer)
- FutureProvider
- StreamProvider
Correct answer: Provider
Provider in Riverpod is used to expose read-only, computed, or dependency-injected values.
Question 2: In Riverpod, what is the role of ConsumerWidget?
- It creates a new provider scope
- It allows a widget to read and watch Riverpod providers (Correct answer)
- It disposes providers automatically
- It merges multiple providers
Correct answer: It allows a widget to read and watch Riverpod providers
ConsumerWidget replaces StatelessWidget and provides a WidgetRef to watch and read providers.
Question 3: What does the ref.watch() method do in Riverpod?
- Reads a provider once without listening for changes
- Subscribes to a provider and rebuilds the widget when it changes (Correct answer)
- Disposes a provider
- Creates a new provider
Correct answer: Subscribes to a provider and rebuilds the widget when it changes
ref.watch() subscribes the widget to a provider so it rebuilds whenever the provider's state changes.
Question 4: Which package provides a Redux-like state management solution for Flutter with strict unidirectional data flow?
- provider
- redux (Correct answer)
- mobx
- get
Correct answer: redux
The redux package implements the Redux pattern with a single store, reducers, and actions.
Question 5: In GetX state management, which class do you extend to create a reactive controller?
- ChangeNotifier
- GetxController (Correct answer)
- StateNotifier
- BlocBase
Correct answer: GetxController
GetxController is the base class for GetX controllers, providing lifecycle hooks and reactive state.
Question 6: What is the purpose of the freezed package commonly used with Flutter state management?
- To freeze app frames for testing
- To generate immutable data classes and union types (Correct answer)
- To cache network responses
- To disable hot reload
Correct answer: To generate immutable data classes and union types
freezed generates immutable value classes with copyWith(), equality, and union/sealed class support via code generation.
Which Riverpod provider should you use to expose a simple immutable value?