deferred_type for Dart

Pub Version GitHub

Modeling asynchronous data in Dart made easy. This package also provides various useful helper functions for transforming and querying the contained values.

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


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!');

Sample MV app:

import "package:deferred_type/deferred_type.dart";

class App {
  Deferred<String> state = Deferred.idle();

  App() {

  Future<void> getStatus() async {
    state = Deferred.inProgress();
    try {
      final someData = await Future.value("some data");
      state = Deferred.success(someData);
    } catch (e) {
      state = Deferred.error(e, null);

  String view(Deferred<String> state) {
    return state.when(
      success: (data) => "Got data: $data",
      error: (msg, stackTrace) => "Error: $msg",
      inProgress: () => "Loading...",
      idle: () => "Initializing...",

  String render() {
    final template = view(state);
    return template;

API Reference

Detailed API documentation can be found on

Possible to-do

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

Other resources


This project is MIT licensed.