Skip to content

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!);
},
)

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.

ParameterTypeDefaultDescription
future:Future<T>?requiredThe 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>requiredBuilds the subtree from the latest connection state, data, or error.

FutureBuilder is defined in packages/fleury/lib/src/widgets/async.dart.

Category: State & async · All widgets