StateView class
Picks what to render based on the current ViewState, and cross-fades between states as it changes.
Instead of scattering if (loading) ... else if (error) ... across your
build methods, describe each case once and switch on a single value:
StateView(
state: state,
loading: const LoadingState(),
empty: const EmptyState(title: 'No products found'),
error: ErrorState(onAction: _retry),
noInternet: NoInternetState(onRetry: _retry),
child: ProductList(products: products),
)
Any slot you leave out falls back to a sensible default, so you only fill in the ones you want to customise. Pass onRetry and the default error and no-internet states come pre-wired with a working retry button:
StateView(state: state, onRetry: _load, child: ProductList(...))
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- StateView
Constructors
Properties
- animate → bool
-
Whether to cross-fade when state changes. Defaults to
true, and is skipped automatically when the OS "reduce motion" setting is on.final - child → Widget?
-
Shown for ViewState.content — your actual screen.
final
- duration → Duration
-
Duration of the cross-fade between states.
final
- empty → Widget?
-
Shown for ViewState.empty. Defaults to an EmptyState.
final
- error → Widget?
-
Shown for ViewState.error. Defaults to an ErrorState.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- loading → Widget?
-
Shown for ViewState.loading. Defaults to a LoadingState.
final
- noInternet → Widget?
-
Shown for ViewState.noInternet. Defaults to a NoInternetState.
final
-
onRetry
→ FutureOr<
void> Function()? -
Wires the retry button of the default error and noInternet widgets,
so the common case needs no explicit
ErrorStateat all. Ignored for slots you've filled in yourself. Returning a Future shows inline progress on the button until it completes.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → ViewState
-
Which state to show right now.
final
- transitionBuilder → AnimatedSwitcherTransitionBuilder?
-
Customises the transition between states — same contract as
AnimatedSwitcher.transitionBuilder. Defaults to a cross-fade.
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
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.
override
-
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, int wrapWidth = 65}) → 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