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

パッケージ詳細v0.10.0

flutter_state_management

状態管理における ChangeNotifier の使用を簡単にするためのヘルパークラスのコレクション

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
296
いいね数
4
Pub ポイント
160

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

flutter pub add flutter_state_management

パッケージ概要

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

ChangeNotifier を扱うためのヘルパークラスを提供することで、Flutter における状態管理を簡素化する軽量パッケージです。ボイラープレートコードを削減し、アプリの状態管理時の開発者の生産性を向上させます。Flutter のリアクティブフレームワークとシームレスに統合されるように設計されており、Android、iOS、Web、macOS、Windows、Linux などすべての主要プラットフォームをサポートしています。より大きな状態管理ソリューションの複雑さを避けながら、最小限で洗練された状態処理アプローチを求める開発者にとって理想的です。

用途

  • 小さなアプリにおけるシンプルな状態の更新
  • ChangeNotifier 実装におけるボイラープレートの削減
  • フォームおよびUIコンポーネントにおける状態ロジックの最適化
  • 複数のウィジェット間で共有データを管理する
  • BLoC や Provider の軽量な代替手段

主な機能

  • ChangeNotifier のヘルパークラス
  • 最小限のセットアップとインテグレーション
  • クロスプラットフォーム対応
  • きれいで読みやすいコード構造
  • 一般的な状態パターン向けの組み込みユーティリティ

適している対象

  • 初心者のFlutter開発者
  • 小規模から中規模のプロジェクト
  • 基本的な状態管理が必要なアプリ
  • 複雑さよりも単純さを好む開発者
  • 迅速なプロトタイピングを望むチーム

注意事項

  • 複雑な状態フローには適していません
  • 機能豊富な状態管理ライブラリと比べて制限されている
  • 大規模なアプリには追加のツールが必要になる場合があります
  • スケーリングする際には、他の状態管理アプローチと併用するのが最適です
  • 組み込みの永続性や非同期処理を含まない

元の README

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

Flutter State Management

Just a couple of utility classes to make it easier to use Flutter framework's built-in ChangeNotifier and Listenable for state management.

Features

  • No learning curve if you already know Flutter
  • Simple package based on ChangeNotifier (No bloatware)

Usage

Create your model class

class Counter extends StateNotifier<int, String> {
  Counter() : super(const Active(data: 0));

  void increment() async {
    setWaiting();

    await Future.delayed(const Duration(seconds: 2));

    if (data > 20) {
     setFailed('greater than 20');
    } else {
      setActive(data + 1);
    }
  }
}

Or if you want the state to persist across restarts

class Counter extends PersistedStateNotifier<int, String> {
  Counter() : super(IsarKeyValue(), startState: 0);

  void increment() async {
    setWaiting();

    await Future.delayed(const Duration(seconds: 2));

    if (data > 20) {
      setFailed('greater than 20');
    } else {
      setActive(data + 1);
    }
  }
}

Handle State Changes in UI

To only rebuild specific parts:
  1. Use ValueListenableBuilder from the Flutter framework:
final counter = Counter();

ValueListenableBuilder(
  valueListenable: counter,
  child: Text()
  builder: (context, state, child) => // return updated UI here (can also use counter.builderArg here)
  child: const Text('Hello'),
  ),
);

You can also use builderArg helper:

builder: counter.builderArg(
  onActive: ,
  onWaiting: ,
  onNone: ,
  onFailure: ,
),
  1. Or use StateNotifierBuilder that comes with this package and is more user friendly:
final counter = Counter();

counter.builder(
  onActive: (context, data) => Text(data.toString()),
),


\

To rebuild whole widget

Convert your existing StatelessWidget to RStatelessWidget, and StatefulWidget to RStatefulWidget and and just watch the model inside the build method:

class CounterText extends RStatelessWidget {
  @override
  Widget build(BuildContext context) {
    counter.watch(context); // call watch inside the build method (do not use any if) 
    return Text(data.toString());
  }
}

カテゴリー

ソースリポジトリ

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

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