forEachState method
To externally 'process' through the State objects.
Invokes func
on each StateX possessed by this StateX object.
With an option to process in reversed chronological order
Implementation
bool forEachState(void Function(StateX state) func, {bool? reversed}) {
bool each = true;
Iterable<StateX> list;
// In reversed chronological order
if (reversed != null && reversed) {
list = _MapOfStates._states.values.toList(growable: false).reversed;
} else {
list = _MapOfStates._states.values.toList(growable: false);
}
for (final StateX state in list) {
try {
if (state.mounted && !state.deactivated) {
func(state);
}
} catch (e, stack) {
each = false;
// Record the error
if (this is StateX) {
(this as StateX).recordException(e, stack);
}
}
}
return each;
}