easy_isolate_mixin
FlutterでDartのisolatesを起動するための簡略化されたミックスインで、Flutterプラグインとシームレスに連携します
FlutterでDartのisolatesを起動するための簡略化されたミックスインで、Flutterプラグインとシームレスに連携します
以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。
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.
To use the Easy Isolate Mixin package in your Flutter project, follow these steps:
Add the following line to your project's pubspec.yaml file under the dependencies section:
dependencies:
easy_isolate_mixin: ^1.0.0
Run the following command in your terminal or command prompt:
$ flutter pub get
Add the following import statement to your Dart code:
import 'package:easy_isolate_mixin/easy_isolate_mixin.dart';
import 'package:easy_isolate_mixin/easy_isolate_mixin.dart';
IsolateHelperMixin:class Service with IsolateHelperMixin {
// Your methods and logic here
}
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.
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.
依存関係一覧 1 件
{"sdk":"flutter"}用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗