restoreSnapshot method

  1. @override
void restoreSnapshot(
  1. StateSnapshot<T> snapshot
)
override

Restores the state from a previously created snapshot.

This will update the current value to match the snapshot and notify listeners of the change.

Implementation

@override
void restoreSnapshot(StateSnapshot<T> snapshot) {
  if (_isDisposed) throw StateError('MockState has been disposed');
  if (_shouldThrowOnRestore) {
    throw _customException ?? Exception('Mock restore error');
  }

  final oldValue = _value;
  _value = snapshot.value;

  _changeHistory.add(StateChangeEvent(
    previousValue: oldValue,
    newValue: snapshot.value,
    timestamp: DateTime.now(),
    source: 'MockState.restoreSnapshot',
  ));

  _notifyListeners();
}