Describe the bug
When I define a StateProvider as a list, an add or remove doesn't trigger the watch.
To Reproduce
final goalStates = StateProvider(
(_) => [
GoalState.ACTIVE,
],
);
final _states = watch(goalStates);
onPressed: () {
_states.state.add(GoalState.COMPLETE);
_states.state = _states.state;
},
It doesn't trigger on the .add line, but it does on the = line
Expected behavior
Shouldn't it also trigger on the add?
@arnoutvandervorst That is expected. The state instance is the same even though you add elements to the list. You are just mutating the list.
To detect changes you should make new instances of your list.
_states.state = _states.state.toList()..add(...)
This is indeed expected
On the other hand I wonder if during development StateProvider should detect that the value is a list and wrap it in an UnmodifiableListView
This would throw an error instead of failing silently
Most helpful comment
This is indeed expected
On the other hand I wonder if during development StateProvider should detect that the value is a list and wrap it in an
UnmodifiableListViewThis would throw an error instead of failing silently