ResourceBuilder API docs

Reacts to the resource calling the builder each time.

final counter = Resource(
  fetcher: () => Future.value(1),

Widget build(BuildContext context) {
  return ResourceBuilder(
    resource: counter,
    builder: (context, counterState) {
      return switch (counterState) {
        ResourceReady(:final value) => Text(value),
        ResourceError(:final error, :final stackTrace) =>
          Text('$error, $stackTrace'),
        ResourceLoading() => const CircularProgressIndicator(),


  required Resource<T> resource,
  required ResourceWidgetBuilder<T> builder,

resource is the resource that will be rendered based on its state.

builder is the function that builds the widget with the current state of the resource.