Offers a ResourceFutureBuilder that handles a Future<Resource> and handles the result by calling the passed methods for onSuccess, onLoading and onError depending on the state.

Usage

Use a ResourceFutureBuilder like this:

import 'package:flutter/material.dart';
import 'package:resource_future/resource_future.dart';
import 'package:resource_result/resource_result.dart';

final Future<Resource<int>> getSomeIntFuture = Future.value(Success(3));
// or final Future<Resource<int>> getSomeIntFuture = Future.value(Failure(Error("I failed"));

final myIntResourceFutureBuilder = ResourceFutureBuilder(
  future: getSomeIntFuture,
  success: (context, myInt) => Text("My int loaded successfully: $myInt"),
  loadingIndicator: (context) => const CircularProgressIndicator(),
  /* optional handleError: defaults to red Text with error message */
  handleError: (context, error) =>
      Text("Failed to get my int :(. ${error.message}"),
);