Last updated:
0 purchases
resource widget
Offers a ResourceFutureBuilder that handles a Future<Resource<T>> and handles the result by calling
the passed methods for onSuccess, onLoading and onError depending on the state.
Offers a StreamBuilder<T> that handles a Stream<Resource<T>> 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_widget/resource_widget.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}"),
);
copied to clipboard
Use a ResourceStreamBuilder like this:
final Stream<Resource<int>> someIntStream = Stream.fromIterable(
[Loading(null), Success(3), Failure.fromMessage("Failed")]);
final myIntResourceStreamBuilder = ResourceStreamBuilder(
stream: someIntStream,
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}"));
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.