didUpdateRestorationId method Null safety

  1. @protected
void didUpdateRestorationId()

Must be called when the value returned by restorationId changes.

This method is automatically called from didUpdateWidget. Therefore, manually invoking this method may be omitted when the change in restorationId was caused by an updated widget.

Implementation

@protected
void didUpdateRestorationId() {
  // There's nothing to do if:
  //  - We don't have a parent to claim a bucket from.
  //  - Our current bucket already uses the provided restoration ID.
  //  - There's a restore pending, which means that didUpdateDependencies
  //    will be called and we handle the rename there.
  if (_currentParent == null || _bucket?.restorationId == restorationId || restorePending) {
    return;
  }

  final RestorationBucket? oldBucket = _bucket;
  assert(!restorePending);
  final bool didReplaceBucket = _updateBucketIfNecessary(parent: _currentParent, restorePending: false);
  if (didReplaceBucket) {
    assert(oldBucket != _bucket);
    assert(_bucket == null || oldBucket == null);
    oldBucket?.dispose();
  }
}