loading_value 0.0.3 copy "loading_value: ^0.0.3" to clipboard
loading_value: ^0.0.3 copied to clipboard

A declarative implementation of a loading value

A simple, declarative wrapper class for a value that is loading and will return a value at some point. Similar to Rémi Rousselet's AsyncValue used in riverpod and flutter_hooks.

Features #

Use a single stream to easily represent all states that happen during loading:


Stream<LoadingValue<bool>> loadResult() async* {
  Stream<double> progressHandler = const Stream<double>();
  try {
    final result = someFunction(progressHandler);
    await for (final progress in progressHandler) {
      yield LoadingValue<bool>.loading(progress);
    }
    yield LoadingValue.data(await result);
  } catch (e, s) {
    yield LoadingValue<bool>.error(e, stackTrace: s);
  }
}

0
likes
140
pub points
1%
popularity

Publisher

verified publishertimcreated.it

A declarative implementation of a loading value

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

meta

More

Packages that depend on loading_value