Offers a ResourceBuilder
that handles a Resource<T>
and handles the result by calling
the passed methods for onSuccess, onLoading and onError depending on the state.
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 ResourceBuilder
like this:
import 'package:flutter/material.dart';
import 'package:resource_widget/resource_widget.dart';
import 'package:resource_result/resource_result.dart';
final myIntResourceBuilder = ResourceBuilder(
resource: myIntResource,
success: (context, myInt) => Text("My int loaded successfully: $myInt"),
loadingIndicator: (context, data) => const CircularProgressIndicator(),
failureBuilder: (context, message) =>
Text("Failed to get my int :(. $message"),
);
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, data) => const CircularProgressIndicator(),
/* optional handleError: defaults to red Text with error message */
failureBuilder: (context, message) =>
Text("Failed to get my int :(. $message"),
);
Use a ResourceStreamBuilder
like this:
final myIntResourceStreamBuilder = ResourceStreamBuilder(
stream: someIntStream,
success: (context, myInt) => Text("My int loaded successfully: $myInt"),
loadingIndicator: (context, data) => const CircularProgressIndicator(),
/* optional handleError: defaults to red Text with error message */
failureBuilder: (context, message) =>
Text("Failed to get my int :(. $message"));