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

パッケージ詳細v1.0.1

easy_isolate_mixin

FlutterでDartのisolatesを起動するための簡略化されたミックスインで、Flutterプラグインとシームレスに連携します

AndroidiOSmacOSWindowsLinux
30日間ダウンロード
981
いいね数
34
Pub ポイント
160

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

flutter pub add easy_isolate_mixin

パッケージ概要

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

EasyIsolateMixin は、Flutter/Dart パッケージであり、イソレートの作成と管理を簡素化し、メインスレッドをブロッキングせずに効率的なバックグラウンド処理を可能にします。Flutter プラグインとシームレスに統合され、ファイル処理、データパース、または重い計算などの計算集約型タスクに最適です。ミックスインパターンによりボイラープレートコードを削減し、メッセージ送信を通じてイソレート間の通信を簡素化します。クロスプラットフォーム対応で、Android、iOS、macOS、Windows、Linux をサポートしており、デバイス間で一貫した動作を保証します。

用途

  • Flutter アプリにおけるバックグラウンド計算
  • UIのフリーズを引き起こさずに大規模なデータセットを処理する
  • IsolatesでのFlutterプラグインとの統合
  • 複数のプラットフォームでCPU集約的なタスクを実行する
  • 隔離ライフサイクル管理の簡素化

主な機能

  • 簡単な統合のためのミックスインベースの API
  • スムーズなプラグイン互換性
  • クロスプラットフォーム対応
  • 隔離セットアップのボイラープレートを削減
  • 隔離間の組み込みメッセージ処理

適している対象

  • シンプルなイソレート使用を求める開発者
  • バックグラウンド処理を必要とするアプリ
  • クリーンで保守しやすいコードを重視するチーム
  • Flutterプラグインを広く利用するプロジェクト
  • クロスプラットフォームのモバイルおよびデスクトップアプリケーション

注意事項

  • Dartの隔離領域の概念を理解する必要があります
  • 適切な設計がなければ、I/O集約的な操作には向かない
  • メッセージ渡し通信モデルに限定
  • 複雑なワークフローでは追加のエラー処理が必要になる場合があります
  • CPUバウンドタスクをオフロードする場合に最適です

元の README

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

Easy Isolate Mixin

The Easy Isolate Mixin is a powerful mixin package designed to streamline the usage of isolates in your Flutter applications. With this Package, you can easily leverage isolates to perform concurrent and computationally intensive tasks without blocking the main thread.


Platform Pub Package License: MIT


Key Features

  • 🔑 Extremely easy to use
  • 👨‍👦‍👦 Efficient Isolate Management
  • 🔥 Enhanced Performance
  • 🥶 Prevents your UI from freezing
  • 🛠 Scalability enabled by mixins

Installing

To use the Easy Isolate Mixin package in your Flutter project, follow these steps:

  1. Depend on it

Add the following line to your project's pubspec.yaml file under the dependencies section:

dependencies:
  easy_isolate_mixin: ^1.0.0
  1. Install it

Run the following command in your terminal or command prompt:

$ flutter pub get
  1. Import it

Add the following import statement to your Dart code:

import 'package:easy_isolate_mixin/easy_isolate_mixin.dart';

Usage

  1. Import the package:
import 'package:easy_isolate_mixin/easy_isolate_mixin.dart';
  1. Create a class and mixin the IsolateHelperMixin:
class Service with IsolateHelperMixin {
  // Your methods and logic here
}
  1. Use the loadWithIsolate() method to perform expensive work:
class Service with IsolateHelperMixin {
  Future<void> performExpensiveWork() async {
    final result = await loadWithIsolate(() async{
      // Perform your expensive work here
      // Return the result
    });
    
  }
}

In the performExpensiveWork() method, you can use the loadWithIsolate() method from the IsolateHelperMixin to perform your expensive work in a separate isolate. Simply pass a function to loadWithIsolate() that contains your expensive computation. The result of the computation will be returned as a Future.

Handling Big Data

Here's an example of using loadWithIsolate() to fetch a list of SomeData objects:

class DataSource with IsolateHelperMixin {
  Future<List<SomeData>> fetchAmountOfData() => 
  loadWithIsolate(() => _api.getAmountOfData());
}

The _api.getAmountOfData() function represents your data fetching logic. It will be executed in a separate isolate, allowing your UI to remain responsive while the data is being fetched. The result will be returned as a Future<List<SomeData>>.

Note: Make sure the function you pass to loadWithIsolate() returns a value or a Future that resolves to the desired result type.

That's it! You can now leverage the power of isolates to perform concurrent and computationally intensive tasks without blocking the main thread.

カテゴリー

ソースリポジトリ

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