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

パッケージ詳細v1.0.8

dash

Dash ライブラリは、Bloc の提供と破棄を管理するサービスロケーターパターンを提供する責任があります。

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

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

flutter pub add dash

パッケージ概要

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

Dash は、Flutter用の軽量なサービスロケーターパッケージであり、blocのライフサイクルを管理することで、依存関係のインジェクションを簡素化し、適切なインスタンス化と破棄を保証します。特にBlocパターンによる状態管理に適した、依存関係の登録および取得をクリーンに実行する方法を提供します。このライブラリはすべての主要プラットフォームをサポートしており、既存のFlutterプロジェクトにシームレスに統合できます。ライフサイクルへの配慮により、メモリリークを防ぎ、アプリのパフォーマンスを向上させます。

用途

  • FlutterアプリにおけるBlocのライフサイクルの管理
  • 依存関係の注入を簡素化する
  • 手動での Bloc の作成と破棄の置き換え
  • 状態管理パターンとの統合
  • テストセットアップの簡素化
  • モジュールアーキテクチャアプリの有効化

主な機能

  • 自動的な bloc 解放
  • 簡単な登録と取得
  • プラットフォームに依存しない設計
  • 組み込みライフサイクル管理
  • 最小限のボイラープレート
  • ネストされた依存関係をサポートします

適している対象

  • Bloc パターンを使用する Flutter 開発者
  • 構造化された依存関係管理を必要とするアプリ
  • 軽量なDIソリューションを求めるチーム
  • クリーンな状態管理を目指すプロジェクト
  • 自動リソースクリーンを希望する開発者

注意事項

  • ブロックスに焦点を当てた利用ケースに限定
  • サービスロケーターパターンの理解が必要です
  • 複雑なDIのニーズには適していません
  • 高度なシナリオ用に追加のセットアップが必要になる場合があります
  • 完全なDIフレームワークよりも機能が少ない

元の README

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

Dash

Logo

Dash is a simple but efficient library that helps provide BloCs without headaches.

IMPORTANT: Dart2 is required to use this package.

Installation

  • Add dash to your pubspec.yaml under the dependencies section:
dependencies:
  dash: ^latest_version
  • Add build_runner and dash_generator to your pubspec.yaml under the dev_dependencies section:
dev_dependencies:
  build_runner: ^2.0.3
  dash_generator: ^latest_version

Usage

1 - Create a provider class that will gather BlocProvider annotation:

IMPORTANT: Do not forget to add: part 'provider.g.dart';.

import 'package:dash/dash.dart';

part 'provider.g.dart';

@BlocProvider.register(MySampleBloc)
@BlocProvider.register(MyOtherBloc)
abstract class Provider {}

2 - Extend BLoCs from Bloc. It will allow you to override dispose method.

IMPORTANT: All blocs must have an instance() function that returns the instance of the bloc as below.

class MySampleBloc extends Bloc {

  @override
  dispose() {
    //close all streams
  }

  static Bloc instance() => MySampleBloc();
  
}

class MyOtherBloc extends Bloc {

  @override
  dispose() {
    //close all streams
  }

  static Bloc instance() => MyOtherBloc();
}

3 - Run build_runner, it will generate the provider.g.dart class that you added as part on your provider class.

On project directory run in terminal:

pub run build_runner build

For flutter:

flutter packages pub run build_runner build

Note: If you encounter a conflict error, please add the --delete-conflicting-outputs argument to your command:

flutter packages pub run build_runner build --delete-conflicting-outputs

4 - Finally you can get your BLoC instance from anywhere, for example:

  @override
  Widget build(BuildContext context) {
    final _bloc = $Provider.of<MyOtherBloc>();

    return Container();
  }

  @override
  void dispose() {
    $Provider.dispose<MyOtherBloc>();
    super.dispose();
  }

Changelog

Please see the Changelog page to know what's recently changed.

カテゴリー

ソースリポジトリ

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

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