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

パッケージ詳細v3.0.4

stream_mixin

Flutter の State/setState/StatefulWidget を使用せずに、ストリームを使用した状態管理により、パフォーマンスの向上とコードの分離を実現します。

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

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

flutter pub add stream_mixin

パッケージ概要

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

StreamMixin は、Flutter の状態管理ソリューションであり、StatefulWidget や setState、従来の状態付きウィジェットの必要性を排除するためにストリームを利用しています。ストリームベースの更新を統合することで、パフォーマンスを向上させ、コードの分離をより明確にします。このパッケージは、シンプルなミックスインを通じてリアクティブな状態処理を可能にし、状態変更をより予測可能かつテストしやすくします。組み込みの状態管理パターンに対する軽量で効率的な代替手段を探している開発者にとって理想的です。

用途

  • StatefulWidget を使わないリアクティブな UI の更新
  • 小規模から中規模のアプリ向けの軽量な状態管理
  • 状態ロジックのテスト性の向上
  • ビジネスロジックとUIの分離
  • リアルタイムデータ同期
  • 複雑な状態遷移の簡略化

主な機能

  • ストリームベースの状態更新
  • setState や StatefulWidget が必要ありません
  • 既存コードとの簡単な統合
  • ホットリロードおよびデバッグをサポートしています
  • 関心事の明確な分離を促進する
  • 最小限のボイラープレート

適している対象

  • StatefulWidgetの複雑さを避けようとする開発者
  • パフォーマンスとスケーラビリティを重視するプロジェクト
  • リアクティブプログラミングパターンを使用するチーム
  • リアルタイムデータ処理を必要とするアプリケーション
  • 軽量な状態ソリューションを探している人
  • Flutterの初心者が反応型の概念を学ぶ

注意事項

  • Dart のストリームについての理解が必要です
  • ストリームのサブスクリプションに対して追加のエラー処理が必要になる場合があります
  • 非常に大きなステートツリーには適していない
  • 完全なフレームワークと比べて、組み込みの開発ツールが限られている
  • 反応型パターンに馴染みのない開発者向けの学習曲線
  • ストリームが適切に管理されない場合、メモリリークの可能性があります

元の README

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

stream_mixin

State management using stream to avoid use of flutter's State/setState/StatefulWidget, boosting the performance and code separation.

Breaking change in 2.0.0 and 3.0.0. Check the changelog.

The Intention

The intention for this package is to use stream instead of flutter's state for streaming data from the controller/adapter/service class to the widgets, which results in better performance and cleaner code.

Basic example

A basic example of a counter service that increments the count and streams the count to the widget

class Counter with StreamMixin<int> {
  increment() {
    update((lastUpdate ?? 0) + 1);
  }
}

/// You can either create a global instance of Counter or create a
/// singleton (recommented) like class by adding the following in Counter class
/// ```dart
///   Counter._();
///   static Counter instance = Counter._();
/// ```
final counter = Counter();

anywhereInTheApp() {
  counter.increment();
}

Widget someWidget() {
  return StreamBuilder<int>(
    stream: counter.onChange,
    builder: (cxt, snap) => Text((snap.data ?? 0).toString()),
  );
}

Contribute ❤️

There are couple of ways in which you can contribute.

  • Propose any feature, enhancement
  • Report a bug
  • Fix a bug
  • Participate in a discussion and help in decision making
  • Write and improve some documentation. Documentation is super critical and - its importance cannot be overstated!
  • Send in a Pull Request 🙂

カテゴリー

ソースリポジトリ

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