deferred_type

Creator: coderz1093

Last updated:

0 purchases

deferred_type Image
deferred_type Images
Add to Cart

Description:

deferred type

deferred_type for Dart #


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.
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!');
copied to clipboard
Sample MV app:
import "package:deferred_type/deferred_type.dart";

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

App() {
getStatus();
render();
}

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);
}
render();
}

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);
print(template);
return template;
}
}
copied to clipboard
API Reference #
Detailed API documentation can be found on pub.dev.
Possible to-do #

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

Other resources #

Comprehensive functional programming library for Dart: https://github.com/SandroMaglione/fpdart.
Datum library for TypeScript compatible with fp-ts: https://github.com/nullpub/datum.
Alternative, similar package on pub.dev: https://pub.dev/packages/remote_state.

License #
This project is MIT licensed.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.