restoreState method

  1. @override
void restoreState(
  1. RestorationBucket? oldBucket,
  2. bool initialRestore
)
override

Called to initialize or restore the RestorablePropertys used by the State object.

This method is always invoked at least once right after State.initState to register the RestorablePropertys with the mixin even when state restoration is turned off or no restoration data is available for this State object.

Typically, registerForRestoration is called from this method to register all RestorablePropertys used by the State object with the mixin. The registration will either restore the property's value to the value described by the restoration data, if available, or, if no restoration data is available - initialize it to a property-specific default value.

The method is called again whenever new restoration data (in the form of a new bucket) has been provided to the mixin. When that happens, the State object must re-register all previously registered properties, which will restore their values to the value described by the new restoration data.

Since the method may change the value of the registered properties when new restoration state is provided, all initialization logic that depends on a specific value of a RestorableProperty should be included in this method. That way, that logic re-executes when the RestorablePropertys have their values restored from newly provided restoration data.

The first time the method is invoked, the provided oldBucket argument is always null. In subsequent calls triggered by new restoration data in the form of a new bucket, the argument given is the previous value of bucket.

Implementation

@override
void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
  registerForRestoration(_errorText, 'error_text');
  registerForRestoration(_hasInteractedByUser, 'has_interacted_by_user');
}