Skip to content

timcreatedit/loading_value

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A declarative implementation of a loading value heavily inspired by @rrousselGit's AsyncValue

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages