didToggleBucket method Null safety

  1. @override
void didToggleBucket(
  1. RestorationBucket? oldBucket
)
override

Called when bucket switches between null and non-null values.

State objects that wish to directly interact with the bucket may override this method to store additional values in the bucket when one becomes available or to save values stored in a bucket elsewhere when the bucket goes away. This is uncommon and storing those values in RestorablePropertys should be considered instead.

The oldBucket is provided to the method when the bucket getter changes from non-null to null. The oldBucket argument is null when the bucket changes from null to non-null.

See also:

  • restoreState, which is called when the bucket changes from one non-null value to another non-null value.

Implementation

@override
void didToggleBucket(RestorationBucket? oldBucket) {
  super.didToggleBucket(oldBucket);
  if (bucket != null) {
    _serializableHistory.update(_history);
  } else {
    _serializableHistory.clear();
  }
}