🧾 Flutter widget allowing easy cache-based data display in a ListView featuring pull-to-refresh and error banners.

Overview

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!

Comments
  • fetcher is called on every flutter build()

    fetcher is called on every flutter build()

    Since 4.2.5, the fecther is called on every flutter build(), which is not desired. It should only be called on initState, pull-to-refresh or if controller.fetch() is manually called.

    Maybe it's because of the fix of #4.

    To reproduce using your example, you can add an action button to the CachedBuildDemo's scaffold's appbar :

    actions: <Widget>[
              IconButton(
                icon: Icon(Icons.add),
                onPressed: () => Navigator.of(context).push(MaterialPageRoute(
                  builder: (_) => Scaffold(
                    body: Text('nothing'),
                  ),
                )),
              )
            ],
    

    When you tap on it, it will open a new page, flutter will call CachedBuildDemo's build(), and fetcher will be called (not desired).

    opened by Nico04 7
  • Can't refresh data

    Can't refresh data

    Using your exemple project, on the CacheBuilder page, using pull-to-refresh OR calling directly controller.fetch() doesn't refresh the data, controller's fetcher function is only call the first time.

    bug 
    opened by Nico04 4
  • Skeleton loading

    Skeleton loading

    Hi ! When there is no data in cache and when the listview is refreshing, could you display a skeleton text loading with the package https://pub.dev/packages/skeleton_text ?

    opened by Ionys320 1
  • Caching strategies

    Caching strategies

    As @marcelgarus already said in https://github.com/marcelgarus/flutter_cached/issues/5#issuecomment-598095137:

    Actually, the current behavior is somewhat intended as a temporary behavior. In the long term, I was thinking about implementing multiple caching strategies that you can choose from (for example, only fetching the first time or fetching only if the last fetch is some amount in the past)

    opened by JonasWanke 0
  • Custom Pull-to-refresh

    Custom Pull-to-refresh

    With your current implementation, it seems that if I have a ListView inside a Column for instance (with a footer), the pull-to-refresh doesn't work.

                 Column(
                    children: <Widget>[
                      Expanded(
                        child: ListView(
                          children: List.generate(20, (index) => Text('$index')),
                          itemExtent: 100,
                        ),
                      ),
                      Text('Footer'),
                    ],
                  );
    

    And if I set hasScrollBody: false, it throws.

    I guess I would have to use the PullToRefersh directly above the ListView, inside the Expanded. Maybe the pull-to-refresh should be optionnal or external, so we can use our custom behaviour ? For instance I could want to implement a custom PullToRefresh component like this.

    Thanks.

    opened by Nico04 4
  • Support limiting the returned list

    Support limiting the returned list

    Use case: In the Schul-Cloud App we want to show a card on the dashboard displaying only the three most recent news entries. We could limit the returned list on UI side but it's more efficient to only load required entitites from the database/network in the first place, especially in combination with pagination.

    opened by JonasWanke 0
Owner
Marcel Garus
I'm studying IT Systems Engineering and working on open source thingies. ✨ Especially excited about Flutter and Rust. 🌮 Feel free to contact me. he/him
Marcel Garus
GetX Architecture for large scale project, This project include - pagination, pull to refresh, localization, network call and advance error handling

GetX Architecture for large scale project, This project include - pagination, pull to refresh, localization, network call and advance error handling

Wai Han Ko 5 Nov 29, 2022
An easy way to use pull-to-refresh.

MJRefresh An easy way to use pull-to-refresh ?? ✍??Release Notes: more details Contents New Features Dynamic i18n Switching SPM Supported Swift Chaini

M了个J 13.7k Dec 29, 2022
Flutter plugin for building pull to refresh effects with PullToRefreshNotification and PullToRefreshContainer quickly.

pull_to_refresh_notification Language: English | 中文简体 widget to build pull to refresh effects. Web demo for PullToRefreshNotification Chinese blog pul

FlutterCandies 165 Dec 28, 2022
News App developed with Flutter featuring beautiful UI, category-based news, story for faster news reading, inbuilt article viewer, share feature, and more.

Ariel News App developed with Flutter featuring beautiful UI, category-based news, story for faster news reading, inbuilt article viewer, share featur

Hash Studios 30 Nov 9, 2022
Memory Cache is simple, fast and global in-memory cache with CRUD features.

Memory Cache Memory Cache is simple, fast and global in-memory cache. Features Create, read, update, delete and invalidate cache. Expirable Cache Gett

Gökberk Bardakçı 6 Dec 25, 2022
⚡ Cache Manager A tidy utility to handle cache of your flutter app like a Boss.

⚡ Cache Manager A tidy utility to handle cache of your flutter app like a Boss. It provides support for both iOS and Android platforms (offcourse). ??

Abhishek Chavhan 10 Oct 25, 2022
A most easily usable cache management library in Dart. With CacheStorage, you can easily manage cache on your application.

A most easily usable cache management library in Dart! 1. About 1.1. Introduction 1.1.1. Install Library 1.1.2. Import It 1.1.3. Use CacheStorage 1.2.

Kato Shinya 1 Dec 13, 2021
A Flutter package for Offers, Promo and Invites banners. Supports Android and Web.

flat_banners A Flutter package for Offers, Promo and Invites banners. Android support Android and Web. Usage To use this plugin, add flat_banners as a

Omprakash Chauhan 3 Apr 13, 2022
Dart package for Async Data Loading and Caching. Combine local (DB, cache) and network data simply and safely.

Stock is a dart package for loading data from both remote and local sources. It is inspired by the Store Kotlin library.

xmartlabs 59 Dec 24, 2022
Iridium-reader-widget - Plug and play reader widget allowing to easily integrate an Iridium viewer inside any app

Plug and play reader widget allowing to easily integrate an Iridium viewer insid

Mantano 15 Dec 31, 2022
Boozin fitness - A sample app to that will pull data from Google Fit to get the steps count and calories burned

boozin_fitness A sample app to that will pull data from Google Fit to get the st

Abhishek Kumar Gupta 1 Nov 23, 2022
Flutter Bidirectional ListView - ListView with items that can be scrolled in both directions with a fixed item count and scroll boundaries.

Flutter Bidirectional ListView ListView with items that can be scrolled and lazy loaded in up and down direction with a fixed item count and scroll bo

Christoph Rothermel 7 May 30, 2022
Flutter ticket pass - A Flutter Widget to display the details of a ticket/pass purchased by customers and display the details of the purchase

ticket_pass_package A Flutter package to display the purchase of a ticket/pass along with additional details such as list of buyers. The source code i

null 40 Aug 13, 2022
Nimbostratus is a reactive data-fetching and client-side cache management library built on top of Cloud Firestore.

Nimbostratus ?? Nimbostratus is a reactive data-fetching and client-side cache management library built on top of Cloud Firestore. The Cloud Firestore

Dan Reynolds 13 Dec 15, 2022
Response Parser makes it easier to parse data and error response from server.

Response Parser makes it easier to parse data and error response from server. Getting started Do you want to write this pretty functions... Future<Eit

Qyre AB 4 Nov 5, 2022
An intuitive Token Parser that includes grammar definition, tokenization, parsing, syntax error and debugging. Implementation based on Lexical Analysis for Dart.

Token Parser An intuitive Token Parser that includes syntax/grammar definition, tokenization and parsing. Implementation based on Lexical Analysis. Re

JUST A SNIPER ツ 2 Dec 15, 2022
Flutter plugin to display a popup menu button widget with handsome design and easy to use.

menu_button Flutter widget to display a popup menu button very simply and easily customizable. Resources Documentation Pub Package GitHub Repository I

Hugo EXTRAT 63 Sep 27, 2022
Data Migrator - provide a universal translator for data by being portable, diverse, and efficient in migrating and converting data across discrete schemas

Data Migrator - provide a universal translator for data by being portable, diverse, and efficient in migrating and converting data across discrete schemas

Tanner Meade 77 Jan 2, 2023