FutureBuilder
Rebuilds with the latest AsyncSnapshot of future.
Learn more: Loading data
Import: package:fleury/fleury.dart, or package:fleury/fleury_core.dart in browser code.
// In your State: create the future once. Calling load() in build would// start a new request on every rebuild.late final Future<List<Item>> _items = load();
// In build:FutureBuilder<List<Item>>( future: _items, builder: (context, snapshot) { if (snapshot.hasError) return Text('Failed: ${snapshot.error}'); if (!snapshot.hasData) return const Text('Loading…'); return ItemList(snapshot.data!); },)Details
Section titled “Details”Create the future once (in initState or a field) and pass the same
instance — building it inline (future: fetch()) re-runs it on every
rebuild, the classic FutureBuilder mistake. This widget re-subscribes
only when the future identity changes, so a stable future is safe.
Constructors
Section titled “Constructors”FutureBuilder()
Section titled “FutureBuilder()”| Parameter | Type | Default | Description |
|---|---|---|---|
future: | Future<T>? | required | The asynchronous computation to observe. A null future stays disconnected. |
initialData: | T? | — | Data exposed before future completes, or null when there is no seed value. |
builder: | AsyncWidgetBuilder<T> | required | Builds the subtree from the latest connection state, data, or error. |
Source
Section titled “Source”FutureBuilder is defined in packages/fleury/lib/src/widgets/async.dart.
Category: State & async · All widgets