saveState method
Implementation
@protected
@mustCallSuper
void saveState() {
final state = (encode ?? jsonEncode)(_data);
if (_index >= 0 && _index < history.length && history[_index] == state) return;
if (_index < history.length - 1) history.removeRange(_index + 1, history.length);
history.add(state);
_index++;
_trimToCapacity();
_updateFlags();
}