flutter_isolate 1.0.0+14

Flutter Android iOS

FlutterIsolate provides a way to launch dart isolate in flutter that work with flutter plugins.

FlutterIsolate #

FlutterIsolate allows creation of an Isolate in flutter that is able to use flutter plugins. It creates the necessary platform specific bits (FlutterBackgroundView on android & FlutterEngine on iOS) to enable the platform channels to work inside an isolate.

FlutterIsolate API #

AndroidiOSDescription
FlutterIsolate.spawn(entryPoint,message)spawns a new FlutterIsolate
flutterIsolate.pause()pauses a running isolate
flutterIsolate.resume()resumed a paused isoalte
flutterIsolate.kill()kills a an isolate

Example #

This is available in the example included with the package.

import 'package:flutter_startup/flutter_startup.dart';
import 'package:flutter_isolate/flutter_isolate.dart';

void isolate2(String arg) {
  FlutterStartup.startupReason.then((reason){
    print("Isolate2 $reason");
  });
  Timer.periodic(Duration(seconds:1),(timer)=>print("Timer Running From Isolate 2"));
}

void isolate1(String arg) async  {

  final isolate = await FlutterIsolate.spawn(isolate2, "hello2");

  FlutterStartup.startupReason.then((reason){
    print("Isolate1 $reason");
  });
  Timer.periodic(Duration(seconds:1),(timer)=>print("Timer Running From Isolate 1"));
}

void main() async {

  final isolate = await FlutterIsolate.spawn(isolate1, "hello");
  Timer(Duration(seconds:5), (){print("Pausing Isolate 1");isolate.pause();});
  Timer(Duration(seconds:10),(){print("Resuming Isolate 1");isolate.resume();});
  Timer(Duration(seconds:20),(){print("Killing Isolate 1");isolate.kill();});

  runApp(MyApp());
}
...

Notes #

Due to a FlutterIsolate being backed by a platform specific 'view', the event loop will not terminate when there is no more 'user' work left to do and FlutterIsolates will require explict termination with kill().

Additionally this plugin has not been tested with a large range of plugins, only a small subset I have been using such as flutter_notification, flutter_blue and flutter_startup.

36
likes
90
pub points
95%
popularity

FlutterIsolate provides a way to launch dart isolate in flutter that work with flutter plugins.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploaders

rmawatson@hotmail.com
ryan@ryanheise.com

License

MIT (LICENSE)

Dependencies

flutter, uuid

More

Packages that depend on flutter_isolate