Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marcelgarus/flutter_cached
๐งพ Flutter widget allowing easy cache-based data display in a ListView featuring pull-to-refresh and error banners.
https://github.com/marcelgarus/flutter_cached
Last synced: 8 days ago
JSON representation
๐งพ Flutter widget allowing easy cache-based data display in a ListView featuring pull-to-refresh and error banners.
- Host: GitHub
- URL: https://github.com/marcelgarus/flutter_cached
- Owner: MarcelGarus
- License: bsd-3-clause
- Created: 2019-10-04T17:59:49.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-12T14:29:27.000Z (over 4 years ago)
- Last Synced: 2024-10-06T17:18:17.436Z (about 1 month ago)
- Language: Dart
- Size: 511 KB
- Stars: 17
- Watchers: 3
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Often, apps just display data fetched from some server.
This package introduces the concept of fetchable streams. They are just like normal `Stream`s, but can be fetched.Let's say you want to load `Fruit`s from a server:
```dart
final stream = FetchStream.create(() {
// Do some network request and parse it to obtain a Fruit.
});
stream.listen(print);// By default, the stream never emits and events. Only after calling fetch(), it
// calls the provided function and emits the result.
stream.fetch();// Calling fetch again executes the function again and provides the result to
// all listeners. If the function is already running, it's not called again.
stream.fetch();// After your're done using the stream, dispose it.
await Future.delayed(Duration(seconds: 10));
stream.dispose();
```The real magic happens by calling `stream.cached()`.
This creates a cached version of this stream using the provided methods.```dart
final cachedStream = stream.cached(
save: (fruit) {
// Save the fruit to storage.
},
load: (fruit) async* {
// Load the fruit from storage and yield it. If there are updates to the
// fruit, you can also optionally yied them too.
},
);
```And that's about it!