rootBucket property
The root of the RestorationBucket
hierarchy containing the restoration
data.
Child buckets can be claimed from this bucket via RestorationBucket.claimChild. If the RestorationManager has been asked to restore the application to a previous state, these buckets will contain the previously stored data. Otherwise the root bucket (and all children claimed from it) will be empty.
The RestorationManager informs its listeners (added via addListener) when the value returned by this getter changes. This happens when new restoration data has been provided to the RestorationManager to restore the application to a different state. In response to the notification, listeners must stop using the old root bucket and obtain the new one via this getter (rootBucket will have been updated to return the new bucket just before the listeners are notified).
The restoration data describing the current bucket hierarchy is retrieved
asynchronously from the engine the first time the root bucket is accessed
via this getter. After the data has been copied over from the engine, this
getter will return a SynchronousFuture, that immediately resolves to the
root RestorationBucket
.
The returned Future may resolve to null if state restoration is currently turned off.
See also:
- RootRestorationScope, which makes the root bucket available in the Widget tree.
Implementation
Future<RestorationBucket?> get rootBucket {
if (_rootBucketIsValid) {
return SynchronousFuture<RestorationBucket?>(_rootBucket);
}
if (_pendingRootBucket == null) {
_pendingRootBucket = Completer<RestorationBucket?>();
_getRootBucketFromEngine();
}
return _pendingRootBucket!.future;
}