dart-isolates

Timer inside flutter isolate not stopping when isolate is killed

懵懂的女人 提交于 2021-01-28 09:53:41
问题 I have an app uploading joystick position data to a webserver using an API call. This method gets called when a joystick is moved. It stops any previously running isolate and starts a new isolate if the joystick is not in the centre. void onJoystickMoved(double angle, double distance) { stopIsolate(); if(distance > 0.06){ startIsolate(JoystickPosition.fromDistanceAndRadius(distance, angle)); } } The isolate start and stop methods Future<void> startIsolate(JoystickPosition position) async {

Flutter: run multiple methods

徘徊边缘 提交于 2021-01-01 06:41:59
问题 I have a big problem. If I want to encrypt my video file, my application is freezing until that method finishing. But there is no error. How can I code my application does not freeze. thanks. Future sifrele() async { String realPath = "/storage/emulated/0/Android/data/com.android.xxxx/files"; var crypt = AesCrypt('sefa'); try { crypt.setOverwriteMode(AesCryptOwMode.on); String encFilepaths = await crypt.encryptFile( realPath + '/WhatCarCanYouGetForAGrand.mp4', realPath + '/video.mp4.aes');

Dart Isolates' pause function not working as expected

南楼画角 提交于 2020-06-25 04:25:05
问题 I've been playing around with Dart Isolates and have run into a problem using the isolate.pause(); function. import 'dart:io'; import 'dart:isolate'; main(){ ReceivePort receivePort = new ReceivePort(); Isolate.spawn(isolateEntryPoint, receivePort.sendPort).then((isolate){ isolate.pause(isolate.pauseCapability); }); } void isolateEntryPoint(SendPort sendPort){ while(true){ print("isolate is running"); sleep(new Duration(seconds: 2)); } } In my example the isolate basically just prints

What thread / isolate does flutter run IO operations on?

独自空忆成欢 提交于 2020-06-08 17:43:10
问题 In flutter when using the http package or doing general IO operations for example import 'package:http/http.dart' as http; http.Response response = await http.get(url); if (response.statusCode == 200) { var json = jsonDecode(response.body); } I have read through The engine architecture which indicates there are 4 threads in the engine Platform Task Runner UI Task Runner GPU Task Runner IO Task Runner The main app dart code runs on the UI Task Runner Thread. The IO task runner seems to be only

Can I pass a BuildContext to Compute?

天大地大妈咪最大 提交于 2020-03-22 09:04:15
问题 Is it possible to use BuildContext inside compute function? Future<int> getFuture() async { int r = await compute(count, context); return r; } static int count(BuildContext context) { // Something very slow. return 10; } I receive the following error when attempting to pass the context to compute : I/flutter ( 8764): AsyncSnapshot<int>(ConnectionState.done, null, Invalid argument(s): Illegal argument in isolate message : (object is a closure - Function '_handleBuildScheduled@374399801':.)) If

What difference between await for(var msg in receivePort) and receivePort.listen()?

不羁岁月 提交于 2020-01-25 12:47:08
问题 I am learning Dart: main() async { ReceivePort receivePort = ReceivePort(); Isolate.spawn(echo, receivePort.sendPort); // await for(var msg in receivePort) // { // print(msg); // } receivePort.listen((msg) { print(msg);} ); } echo(SendPort sendPort) async { ReceivePort receivePort = ReceivePort(); sendPort.send("message"); } I can't understand when it's better to use await for(var msg in receivePort) and when receivePort.listen() ? By the first look it's doing same. Or not? 回答1: I can say it

What difference between await for(var msg in receivePort) and receivePort.listen()?

主宰稳场 提交于 2020-01-25 12:47:05
问题 I am learning Dart: main() async { ReceivePort receivePort = ReceivePort(); Isolate.spawn(echo, receivePort.sendPort); // await for(var msg in receivePort) // { // print(msg); // } receivePort.listen((msg) { print(msg);} ); } echo(SendPort sendPort) async { ReceivePort receivePort = ReceivePort(); sendPort.send("message"); } I can't understand when it's better to use await for(var msg in receivePort) and when receivePort.listen() ? By the first look it's doing same. Or not? 回答1: I can say it

Flutter Isolate image manipulation Memory Issue

*爱你&永不变心* 提交于 2020-01-25 00:25:08
问题 i'm working on a flutter app, which displays a lot of images of unknown aspect-ratio in a list (among other things) to improve the UX a row with an image displays the original image with a blurred version of it in the background (in a stack). To create the blurred version i use the image library (https://pub.dev/packages/image) to not block the UI thread with decoding, blurring and encoding i use isolates But after some testing i've been facing an issue with memory - the Isolate does not seem

Flutter Isolate vs Future

▼魔方 西西 提交于 2020-01-21 06:25:47
问题 I might get the wrong idea of Isolate and Future, please help me to clear it up. Here are my understanding of both subjects. Isolate: Isolates run code in its own event loop, and each event may run smaller tasks in a nested microtask queue. Future: A Future is used to represent a potential value, or error, that will be available at some time in the future. My confusions are: The doc says Isolate has it own loop? I feel like having its own event queue makes more sense to me, am I wrong? Is

Flutter Isolate vs Future

坚强是说给别人听的谎言 提交于 2020-01-21 06:25:05
问题 I might get the wrong idea of Isolate and Future, please help me to clear it up. Here are my understanding of both subjects. Isolate: Isolates run code in its own event loop, and each event may run smaller tasks in a nested microtask queue. Future: A Future is used to represent a potential value, or error, that will be available at some time in the future. My confusions are: The doc says Isolate has it own loop? I feel like having its own event queue makes more sense to me, am I wrong? Is