isolates_helper 0.4.0-dev.1 copy "isolates_helper: ^0.4.0-dev.1" to clipboard
isolates_helper: ^0.4.0-dev.1 copied to clipboard

unlisted

An easy way to create multiple long live isolates for computation, support try-catch block.

example/lib/main.dart

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:isolates_helper/isolates_helper.dart';

import 'functions.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String text = '';

  final isolates = IsolatesHelper(
    concurrent: 3,
    worker: 'worker',
    isDebug: true,
  );

  @override
  void initState() {
    super.initState();
  }

  void calculate() {
    final rand = Random();
    final params = [rand.nextInt(1000), rand.nextInt(1000)];
    isolates(add, params, workerFunction: 'add').then((value) {
      setState(() => text = '$value');
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: Column(
          children: [
            Text('Result: $text'),
            ElevatedButton(onPressed: calculate, child: const Text('Calculate'))
          ],
        )),
      ),
    );
  }
}
7
likes
0
pub points
61%
popularity

Publisher

verified publisherlamnhan.dev

An easy way to create multiple long live isolates for computation, support try-catch block.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

isolate_manager

More

Packages that depend on isolates_helper