Deferred type for Dart

Modeling asynchronous data made easy. Comes with a FutureBuilder2 widget for use in Flutter applications.

Examples

final Deferred<String> idle = Deferred.idle();
final Deferred<String> inProgress = Deferred.inProgress();
final Deferred<String> success = Deferred.success('DATA!');
final Deferred<String> error = Deferred.error('ERROR!');

Flutter

FutureBuilder2, an alternative "FutureBuilder" which is simpler to use than the bundled one provided by default in Flutter.

import "package:deferred_type/deferred_type.dart";

final futureBuilder = FutureBuilder2<String>(
  future: someFuture,
  builder: (context, state) => state.maybeWhen<Widget>(
    inProgress: () => const CircularProgressIndicator(),
    success: (data) => SomeWidget(data),
    error: (error, _stacktrace) => SomeErrorWidget(error),
    // handle fallback cases, must be provided 
    // if all states are not handled.
    orElse: () => const FallbackWidget(),
  );
);

Possible to-do

  • Write some tests.
  • Version with fpdart integration.
  • Come up with a better name for the FutureBuilder.

Other resources

Libraries

deferred
deferred_type
future_builder_deferred