FLUTTER ECOSYSTEM

Xim-ya/easy_isolate_mixin

Flutter에서 Dart Isolate를 시작하기 위한 간소화된 믹스인으로, Flutter 플러그인과 원활하게 작동합니다

easy_isolate_mixin 프로젝트 이미지
Stars
15
Forks
1
최근 푸시(UTC)
2023. 6. 14.
프로젝트 상태
활성
XimYa GitHub avatar
GITHUB User

XimYa ↗

언어Dart

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 1 개
  • flutter{"sdk":"flutter"}

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

README 펼치기 / 접기

Easy Isolate Mixin

https://github.com/aagarwal1012/Animated-Text-Kit/assets/75591730/f9d03a37-c830-45d7-9adb-20bb096f942b

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.