Starts an isolate that launches a second isolate. Both call out to a plugin that uses a method channel on both iOS and android to get the startup reason.
The first isolate is paused after 5 seconds, paused after 10, and killed after 20 seconds. The second continues to print forever.
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());
}
...