cached_streamable 1.0.2+1
cached_streamable: ^1.0.2+1 copied to clipboard
A dead-simple interface for creating a streamable data source.
cached_streamable #
A dead-simple interface for creating a streamable data source.
Think of it as an "extended" StreamController.
Usage #
Create your implementation by extending CachedStreamable.
Use the cache getter and setter to update the value.
You can use any single data type. This example uses int.
class CounterRepository extends CachedStreamable<int> {
CounterRepository() : super(0);
// Some arbitrary future that updates the internal cache
Future<void> increment() =>
Future<void>.delayed(Duration.zero, () => cache = cache + 1);
}
- Use the
streamto access all the updates to the cache.
Future<void> main() async {
// prints "0" when first listened to
final repo = CounterRepository()..stream.listen(print);
// prints "1"
await repo.increment();
}
- Don't forget to call
closewhen you are done.
await repo.close();