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

パッケージ詳細v0.0.6

cubit_base

Bloc/Cubit を使用してデータ取得とページネーションを簡略化する軽量なFlutterライブラリです。標準化された状態と、ボイラープレートを減らすためのFetcherユーティリティを提供します。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
49
いいね数
1
Pub ポイント
155

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

flutter pub add cubit_base

パッケージ概要

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

cubit_base は、Bloc/Cubit パターンにおけるデータ取得およびページネーションを簡素化することを目的とした軽量な Flutter ライブラリです。標準化された状態管理と、繰り返しコードを最小限に抑える内蔵の Fetcher ユーティリティを提供しており、ロード、成功、エラー状態の処理を容易にします。ボイラープレートを減らすことで開発を加速しつつ、クロスプラットフォームでの明確で予測可能な状態遷移を維持します。

用途

  • APIデータ取得の簡素化
  • ページネーション付きリストの実装
  • ステート管理のボイラープレートを減らす
  • 再利用可能なデータプロバイダーの構築
  • 読み込み状態とエラー状態の管理
  • CRUD操作の簡素化

主な機能

  • 一貫したUI処理のための標準状態
  • 非同期操作用の組み込み Fetcher ツール
  • 標準でページネーションをサポート
  • 最小限のセットアップと明確な構造
  • クロスプラットフォーム互換性
  • 関心事の明確な分離

適している対象

  • Bloc/Cubit パターンを使用する開発者
  • 頻繁なデータ取得を必要とするプロジェクト
  • ボイラープレートを減らそうとするチーム
  • ページネーションされたコンテンツを含むアプリ
  • 初心者が状態管理を学ぶ
  • 迅速なプロトタイピングとMVP開発

注意事項

  • Bloc/Cubit に関する知識が必要です
  • 複雑な状態ロジックに対するカスタマイズの制限
  • 非常に動的な状態の流れには適していない
  • 単純なデータ操作に最適
  • 高度なキャッシュのためには追加のレイヤーが必要になる場合があります
  • 完全な機能を実現するために外部の依存関係に依存しています

元の README

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

cubit_base

A lightweight Flutter library to simplify data fetching and pagination using Bloc/Cubit. It provides standardized states and a Fetcher utility to reduce boilerplate in your Clean Architecture features.

Features

  • 🚀 Standardized States: BaseState and BasePaginationState for consistent UI handling.
  • 🔄 Simplified Fetching: Fetcher.fetchWithBase handles loading, success, and error states automatically.
  • 📑 Built-in Pagination: Fetcher.fetchWithPaginate manages page increments and "reached max" logic.
  • 🏗️ Clean Architecture Friendly: Designed to work seamlessly with UseCases and DataStates.

Installation

Add cubit_base to your pubspec.yaml:

dependencies:
  cubit_base: ^0.0.5

Usage

1. Simple Data Fetching

Define your state using BaseState:

class UserState {
  final BaseState<User> user;
  
  UserState({required this.user});
  
  UserState copyWith({BaseState<User>? user}) => UserState(user: user ?? this.user);
}

Use the Fetcher in your Cubit:

Future<void> getUser() async {
  await Fetcher.fetchWithBase<User>(
    fetcher: () => _getUserUseCase.call(),
    state: state.user,
    emitter: (newState) => emit(state.copyWith(user: newState)),
  );
}
2. Pagination

Define your state using BasePaginationState:

class ProductState {
  final BasePaginationState<Product> products;

  ProductState({required this.products});

  ProductState copyWith({BasePaginationState<Product>? products}) =>
      ProductState(products: products ?? this.products);
}

Implement pagination in your Cubit:

Future<void> getProducts({bool isRefresh = false}) async {
  await Fetcher.fetchWithPaginate<Product>(
    fetcher: () => _getProductsUseCase.call(
      params: ProductParams(
        page: isRefresh ? 1 : state.products.query.page,
        size: state.products.query.size,
      ),
    ),
    state: state.products,
    isRefresh: isRefresh,
    emitter: (newState) => emit(state.copyWith(products: newState)),
  );
}

State Components

BaseState<T>

Manages a single object of type T.

  • status: initial, loading, success, error.
  • data: The fetched object.
  • error: Error message if any.
BasePaginationState<T>

Manages a list of type T.

  • list: List of items.
  • status: initial, loading, paging, success, error.
  • query: Contains page and size.
  • reachedMax: Boolean indicating if all data is loaded.

License

This project is licensed under the MIT License - see the LICENSE file for details.

カテゴリー

ソースリポジトリ

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

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