Consider a Flutter app with a counter. Which option correctly describes the difference in UI update behavior when using setState versus Provider for state management?
Think about which widgets get rebuilt when state changes in each method.
setState triggers a rebuild only for the widget where it is called and its descendants. Provider notifies all widgets that listen to the provided state, rebuilding them as needed.
Which statement best explains when to prefer StatefulWidget over Riverpod for state management in Flutter?
Think about the scope and complexity of the state you want to manage.
StatefulWidget is good for simple, local state inside a widget. Riverpod is designed for more complex state that may be shared or needs better organization.
In Flutter, how does state disposal differ between Provider and Bloc when a widget is removed from the widget tree?
Consider how each package manages lifecycle of state objects.
Provider can automatically dispose state objects if configured properly. Bloc typically requires you to call close() or dispose manually to free resources.
Which code snippet correctly updates a Riverpod StateNotifier state in Flutter?
final counterProvider = StateNotifierProvider<CounterNotifier, int>((ref) => CounterNotifier()); class CounterNotifier extends StateNotifier<int> { CounterNotifier() : super(0); void increment() { // Update state here } }
Remember how to update state inside a StateNotifier.
In StateNotifier, you update the state by assigning a new value to the state property. Methods like setState or notifyListeners() are not used here.
A Flutter app uses ChangeNotifierProvider to manage a list of items. After adding a new item, the UI does not update. What is the most likely cause?
Think about what triggers UI rebuilds in ChangeNotifier.
Modifying the list directly without calling notifyListeners() means listeners are not informed of changes, so UI does not rebuild. The other options either cause different issues or are unrelated.