PageStorageModifier class

Establish a subtree in which widgets can opt into persisting states after being destroyed.

PageStorage is used to save and restore values that can outlive the widget. For example, when multiple pages are grouped in tabs, when a page is switched out, its widget is destroyed and its state is lost. By adding a PageStorage at the root and adding a PageStorageKey to each page, some of the page's state (e.g. the scroll position of a Scrollable widget) will be stored automatically in its closest ancestor PageStorage, and restored when it's switched back.

Usually you don't need to explicitly use a PageStorage, since it's already included in routes.

PageStorageKey is used by Scrollable if ScrollController.keepScrollOffset is enabled to save their ScrollPositions. When more than one scrollable (ListView, SingleChildScrollView, TextField, etc.) appears within the widget's closest ancestor PageStorage (such as within the same route), if you want to save all of their positions independently, you should give each of them unique PageStorageKeys, or set some of their keepScrollOffset false to prevent saving.

{@tool dartpad} This sample shows how to explicitly use a PageStorage to store the states of its children pages. Each page includes a scrollable list, whose position is preserved when switching between the tabs thanks to the help of PageStorageKey.

** See code in examples/api/lib/widgets/page_storage/page_storage.0.dart ** {@end-tool}

See also:

Inheritance
Available extensions

Constructors

PageStorageModifier({Key? key, Widget? child, Key? modifierKey, required PageStorageBucket bucket})
Creates a widget that provides a storage bucket for its descendants.
const

Properties

bucket PageStorageBucket
The page storage bucket to use for this subtree.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
modifierKey Key?
The actual key of the widget, which Modifier wrapped
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
inherited
buildWithChild(BuildContext context, Widget? child) Widget
A build method that receives an extra child parameter.
override
createElement() SingleChildStatelessElement
Create a SingleChildStatelessElement
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited