Future Builder
The Future Builder widget is used to build a widget based on the result of a Future
(an asynchronous operation). This is essential for handling data from APIs or other long-running tasks, allowing you to display different widgets for loading, error, and success states.
Properties
Initial Data
The initial data to use while the future is resolving.
AsyncController
An expression to control the future's execution.
Type
The type of future to execute (API
or Delay
).
Duration (ms)
If the Type
is Delay
, this is the duration of the delay in milliseconds.
Data Source
If the Type
is API
, this defines the API endpoint to call.
Actions
On Success
An action to trigger when the future completes successfully.
On Error
An action to trigger if the future completes with an error.
Child of Future Builder
child
The widget to build based on the state of the future. This child widget will have access to variables like futureState
(loading
, error
, completed
) and response
.
Best Practices
Use the
initialData
property to provide a good user experience while the future is resolving.Use a
ConditionalBuilder
as the child of theFutureBuilder
to display different UI for different stream states (e.g., loading, error, data).
Last updated