FutureWorker<T> class

A simplified FutureBuilder wrapper that provides better error handling and loading states.

This widget simplifies the common pattern of handling Future data with loading, error, and empty states. It provides sensible defaults while allowing customization.

Example usage:

FutureWorker<User>(
  future: userService.getUser(id),
  builder: (context, user) => UserCard(user: user),
  errorBuilder: (context, error) => OptionError(
    error: error,
    onRetry: () => setState(() {}),
  ),
  loadingBuilder: (context) => const OptionLoading(),
)
Inheritance
Mixed-in types

Constructors

FutureWorker({Key? key, required Future<T> future, required Widget builder(BuildContext context, T data), bool isProd = false, T? initialData, Widget emptyBuilder(BuildContext context)?, Widget errorBuilder(BuildContext context, Object? error)?, Widget loadingBuilder(BuildContext context)?})
Creates a FutureWorker that listens to the provided future and builds the UI based on its state.
const

Properties

builder Widget Function(BuildContext context, T data)
Builder function called when data is available.
final
emptyBuilder Widget Function(BuildContext context)?
Builder function called when data is null or empty.
final
errorBuilder Widget Function(BuildContext context, Object? error)?
Builder function called when an error occurs.
final
future Future<T>
The future to wait for.
final
hashCode int
The hash code for this object.
no setterinherited
initialData → T?
Initial data to use while waiting for the future.
final
isProd bool
Production mode flag.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
loadingBuilder Widget Function(BuildContext context)?
Builder function called while loading.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

build(BuildContext context) Widget
Builds the UI based on the state of the Future.
override
buildFromSnapshot(BuildContext context, AsyncSnapshot<T> snapshot) Widget
Builds the appropriate widget based on the snapshot state.
inherited
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.
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, 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