Suspense<T> class

Suspense provides a friendly API for using futures in your UI code.

The most common use case for futures is waiting for an API call to return some data, and then formatting and displaying the received data. While the application is waiting for the API call to respond, the user is typically shown a loading component. Sometimes you also need error-handling from the API response. Suspense provides these as properties, and uses FutureBuilder and StreamBuilder under the hood for the implementation.

Inheritance

Constructors

Suspense({Key key, @required Future<T> future, @required Widget fallback, @required Widget builder(T data), Widget errorBuilder(Object error)})
const
Suspense.stream({Key key, @required Stream<T> stream, @required Widget fallback, @required Widget builder(T data), Widget errorBuilder(Object error)})
const

Properties

builder Widget Function(T data)
Builder method for the widget once the Future or Stream returns data.
final
errorBuilder Widget Function(Object error)
Builder method for the widget if the Future or Stream throws an error.
final
fallback Widget
The Widget to be returned if no data has yet been received from the future or stream.
final
future Future<T>
Generic Future object. Will be null If the .stream constructor is used.
final
hashCode int
The hash code for this object.
@nonVirtualread-onlyinherited
key Key
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited
stream Stream<T>
Generic Stream object. Will be null If the regular constructor is used.
final

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
buildFuture() Widget
buildStream() Widget
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.
@protectedinherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent 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.
@nonVirtualinherited