Google Flutter Google Flutter State Management 1 — Questions and Answers
Question 1: Which built-in Flutter class is the simplest way to manage local widget state?
- StatefulWidget (Correct answer)
- InheritedWidget
- Provider
- Bloc
Correct answer: StatefulWidget
StatefulWidget is Flutter's built-in mechanism for managing mutable local state within a widget.
Question 2: What method must you call inside a StatefulWidget to trigger a UI rebuild when state changes?
- rebuild()
- setState() (Correct answer)
- notifyListeners()
- refresh()
Correct answer: setState()
setState() marks the widget as dirty, causing Flutter to schedule a rebuild on the next frame.
Question 3: Which Flutter class allows descendant widgets to access data without passing it explicitly through constructors?
- StatefulWidget
- StatelessWidget
- InheritedWidget (Correct answer)
- Container
Correct answer: InheritedWidget
InheritedWidget propagates data down the widget tree, enabling descendants to access it via context.
Question 4: In the Provider package, which class should you extend to create a simple state object that notifies listeners?
- ChangeNotifier (Correct answer)
- StateNotifier
- ValueNotifier
- StreamController
Correct answer: ChangeNotifier
ChangeNotifier provides the notifyListeners() method that triggers UI rebuilds when state changes.
Question 5: What is the core concept of the BLoC pattern in Flutter?
- Widgets manage their own state directly
- Business logic is separated from UI using Streams (Correct answer)
- State is stored in a global singleton
- Widgets share state via constructors
Correct answer: Business logic is separated from UI using Streams
BLoC (Business Logic Component) uses Streams to separate business logic from the UI layer.
Question 6: Which widget from the Provider package rebuilds only when a specific value changes?
- Consumer
- Selector (Correct answer)
- Provider
- MultiProvider
Correct answer: Selector
Selector rebuilds only when the selected value changes, optimizing performance by avoiding unnecessary rebuilds.
Which built-in Flutter class is the simplest way to manage local widget state?