handleRestorationUpdateFromEngine method Null safety

  1. @protected
void handleRestorationUpdateFromEngine(
  1. {required bool enabled,
  2. required Uint8List? data}
)
protected">@protected

Called by the RestorationManager on itself to parse the restoration information obtained from the engine.

The enabled parameter indicates whether the engine wants to receive restoration data. When enabled is false, state restoration is turned off and the rootBucket is set to null. When enabled is true, the provided restoration data will be parsed into a new rootBucket. If data is null, an empty rootBucket will be instantiated.

Subclasses in test frameworks may call this method at any time to inject restoration data (obtained e.g. by overriding sendToEngine) into the RestorationManager. When the method is called before the rootBucket is accessed, rootBucket will complete synchronously the next time it is called.

Implementation

@protected
void handleRestorationUpdateFromEngine({required bool enabled, required Uint8List? data}) {
  assert(enabled != null);
  assert(enabled || data == null);

  _isReplacing = _rootBucketIsValid && enabled;
  if (_isReplacing) {
    SchedulerBinding.instance.addPostFrameCallback((Duration _) {
      _isReplacing = false;
    });
  }

  final RestorationBucket? oldRoot = _rootBucket;
  _rootBucket = enabled
      ? RestorationBucket.root(manager: this, rawData: _decodeRestorationData(data))
      : null;
  _rootBucketIsValid = true;
  assert(_pendingRootBucket == null || !_pendingRootBucket!.isCompleted);
  _pendingRootBucket?.complete(_rootBucket);
  _pendingRootBucket = null;

  if (_rootBucket != oldRoot) {
    notifyListeners();
    oldRoot?.dispose();
  }
}