flutter_cached 5.0.2
flutter_cached: ^5.0.2

Flutter Android iOS web

🧾 Flutter widget allowing cache-based data display featuring swipe-to-refresh and an error banner.

Often, apps just display data fetched from some server. This package introduces the concept of fetchable streams. They are just like normal Streams, but can be fetched.

Let's say you want to load Fruits from a server:

final stream = FetchStream.create<Fruit>(() {
  // 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.

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!

14
likes
100
pub points
71%
popularity

🧾 Flutter widget allowing cache-based data display featuring swipe-to-refresh and an error banner.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

marcel.garus@gmail.com

License

BSD (LICENSE)

Dependencies

flutter, maybe, meta, pull_to_refresh, rxdart

More

Packages that depend on flutter_cached