didToggleBucket method

  1. @mustCallSuper
  2. @protected
void didToggleBucket(
  1. RestorationBucket? oldBucket

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.


void didToggleBucket(RestorationBucket? oldBucket) {
  // When a bucket is replaced, must `restoreState` is called instead.
  assert(_bucket?.isReplacing != true);