パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.1.0

fl_query

Flutter向けの非同期データキャッシュ、再取得および無効化ライブラリ

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
359
いいね数
38
Pub ポイント
130

パッケージをインストール

flutter pub add fl_query

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

fl_query は、組み込みキャッシュ、自動再フェッチ、キャッシュの無効化を備えた非同期データを管理するためのFlutterパッケージです。データ取得、ロード状態、エラー、キャッシュされた応答を効率的に処理することで、状態管理を簡素化します。リアルタイムまたは頻繁に更新されるデータが必要なアプリに最適で、ボイラープレートコードを削減し、アプリ全体で一貫したデータを保証します。このライブラリはFlutterのリアクティブエコシステムとシームレスに統合され、すべての主要プラットフォームをサポートしています。

用途

  • リアルタイムデータの更新
  • オフライン優先のアプリケーション
  • API データ同期
  • 非同期データを備えたダイナミックな UI
  • API レスポンスのキャッシュ
  • 自動データ更新

主な機能

  • 組み込みキャッシュ
  • 自動リフェッチ
  • キャッシュ無効化
  • 最小限のボイラープレート
  • クロスプラットフォーム対応
  • エラー処理

適している対象

  • 状態管理を使用する開発者
  • 頻繁なAPI呼び出しを持つアプリ
  • オフライン機能を必要とするプロジェクト
  • 開発者の生産性を最優先とするチーム
  • 動的なコンテンツを備えた Flutter アプリ

注意事項

  • async/await パターンの理解が必要です
  • 大きなキャッシュを使用するとメモリ使用量が増える可能性があります
  • 中程度から高頻度のデータに最適
  • 複雑なキャッシュ戦略に対するカスタマイズの制限
  • 単純な静的データには適していません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

"Fl-Query Logo"

Fl-Query

Asynchronous data caching, refetching & invalidation library for Flutter. FL-Query lets you manage & distribute your async data without touching any global state

Fl-Query makes asynchronous server state management a breeze in flutter

Features

  • Async data caching & management
  • Smart + effective refetching
  • Optimistic updates
  • Automatically cached data invalidation & unneeded query/mutation garbage collection
  • Infinite pagination via InfiniteQuery
  • Lazy persistent cache (Uses hive for persisting query results to disk) (optional)
  • Easy to write & understand code. Follows DRY (Don't repeat yourself) convention
  • Compatible with both vanilla Flutter & elite flutter_hooks

Installation

Regular installation:

$ flutter pub add fl_query

For elite flutter_hooks user (Welcome to the flutter cool community btw😎)

$ flutter pub add flutter_hooks fl_query_hooks

Docs

You can find the documentation of fl-query at https://fl-query.krtirtho.dev/

Basic Usage

Initialize the cache databases in your main method

fl-query uses hive for persisting data to disk

void main()async {
  WidgetsFlutterBinding.ensureInitialized();
  await QueryClient.initialize(cachePrefix: 'fl_query_example');
  runApp(MyApp());
}

In MyApp Widget's build method wrap your MaterialApp with with QueryClientProvider widget

  Widget build(BuildContext context) {
    return QueryClientProvider(
      child: MaterialApp(
        title: 'Fl-Query Example App',
        theme: ThemeData(
          useMaterial3: true,
          primarySwatch: Colors.blue,
        ),
        home: const MyHomePage(),
      ),
    );
  }

Let's write use a Query now FL-Query provides a QueryBuilder widget that creates and listens to the specified Query and re-runs the builder function whenever there's an update

It has 2 required parameters(unnamed) key & builder

class MyApp extends StatelessWidget{
    MyApp({super.key});

    @override
    build(context){
      return QueryBuilder<String, dynamic>(
        'hello',
        () {
          return Future.delayed(
              const Duration(seconds: 6), () => 'Hello World!');
        },
        initial: 'A replacement',
        jsonConfig: JsonConfig(
          fromJson: (json) => json['data'],
          toJson: (data) => {'data': data},
        ),
        onData: (value) {
          debugPrint('onData: $value');
        },
        onError: (error) {
          debugPrint('onError: $error');
        },
        builder: (context, query) {
          if (query.isLoading) {
            return const Center(
              child: CircularProgressIndicator(),
            );
          } else if (query.hasError) {
            return Center(
              child: Text(query.error.toString()),
            );
          }
          return Center(
            child: Text(query.data ?? "Unfortunately, there's no data"),
          );
        },
      );
    }
}

And if you're using flutter_hooks you got that too

class MyApp extends HookWidget{
    MyApp({super.key});

    @override
    build(context){
      final query = useQuery<String, dynamic>(
        'hello',
        () {
          return Future.delayed(
              const Duration(seconds: 6), () => 'Hello World!');
        },
        initial: 'A replacement',
        jsonConfig: JsonConfig(
          fromJson: (json) => json['data'],
          toJson: (data) => {'data': data},
        ),
        onData: (value) {
          debugPrint('onData: $value');
        },
        onError: (error) {
          debugPrint('onError: $error');
        },
      );

      if (query.isLoading) {
        return const Center(
            child: CircularProgressIndicator(),
          );
      } else if (query.hasError) {
        return Center(
          child: Text(query.error.toString()),
        );
      }
      return Center(
        child: Text(query.data ?? "Unfortunately, there's no data"),
      );
    }
}

To master the fl-query follow the official blog at https://fl-query.krtirtho.dev/blog

Why?

The hell, why?

The main purpose of Fl-Query is providing the easiest way to manage the messy server-state part requiring the least amount of code with code reusability & performance This let's you focus more on those cool UI animations & transitions✨. Leave the boring stuff to fl-query

Q. Isn't FutureBuilder good?

No, of course not. Unless you're from 2013 or your app is a purely offline app

Q. So FutureProvider from riverpod or provider not enough?

Probably yes. Although riverpod@v2 has added a lot of caching related features but still optimistic updates, periodic refetching & disk persistence are missing. Let's not forget about infinite pagination, it's a nightmare😅. In case of provider, same story. It's a great package but it's not ideal for server-state management

Notice Board

We need some bada** coders to write tests and ruin our life🥲 100% coverage is our goal🙃

カテゴリー

依存関係

依存関係一覧 5 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。