dart-async

Connecting 2 controllers and have access to the first controllers propertie in the second controller

我们两清 提交于 2019-12-10 16:47:39
问题 i have a problem with angular dart. 1 html file to trigger scopes and 2 controller classes index.html ... {{subCtrl.user.name}} ... first controller @Controller( selector: '[mainController]', publishAs: 'mainCtrl' ) class MainController{ User user = new User('testuser'); MainController(); } second controller @Controller( selector: '[subController]', publishAs: 'subCtrl' ) class SubController{ @NgOneWay('user') User user; // constructor SubController(){ getData(); } void getData(){ if(user !=

Dart/Flutter - “yield” inside a callback function

僤鯓⒐⒋嵵緔 提交于 2019-12-10 14:48:09
问题 I need to yield a list for a function; however, I want to yield the list from within a callback function, which itself is inside the main function - this results in the yield statement not executing for the main function, but rather for the callback function. My problem is very similar to the problem that was solved here: Dart Component: How to return result of asynchronous callback? but I cannot use a Completer because I need to yield and not return. The code below should describe the

Getting values from Future instances

穿精又带淫゛_ 提交于 2019-12-10 14:37:22
问题 My data is something like this: { "five": { "group": { "one": { "order": 2 }, "six": { "order": 1 } }, "name": "Filbert", "skill": "databases" }, "four": { "group": { "three": { "order": 2 }, "two": { "order": 1 } }, "name": "Robert", "skill": "big data" }, "one": { "name": "Bert", "skill": "data analysis" }, "seven": { "name": "Colbert", "skill": "data fudging" }, "six": { "name": "Ebert", "skill": "data loss" }, "three": { "name": "Gilbert", "skill": "small data" }, "two": { "name": "Albert

DART: syntax of future then

﹥>﹥吖頭↗ 提交于 2019-12-10 13:02:35
问题 I don´t understand the syntax of the then() clause. 1. myFuture(6).then( (erg) => print(erg) ) What´s (erg) => expr syntactically? I thougt it could be a function, but then( callHandler2(erg) doesn´t work, Error: "Multiple markers at this line - The argument type 'void' cannot be assigned to the parameter type '(String) -> dynamic' - Undefined name 'erg' - Expected to find ')'" 2. myFuture(5).then( (erg) { callHandler(erg);}, onError: (e) => print (e) What´s `onError: (e) => expr"`

Using dart's async with stack_trace's Chain

浪尽此生 提交于 2019-12-08 20:50:29
I'm trying to take advantage of the Chain object provided by stack_trace like so: import 'dart:async'; import 'package:stack_trace/stack_trace.dart'; main() async { print('Hello world: ${console_test.calculate()}!'); Chain.capture(() async { try { await testFunction(); } catch(e,st) { print(Trace.format(new Chain.forTrace(st))); } }); } Future testFunction() async { throw new Exception("TEST"); } The output I get is this: Hello world: 42! main.dart 4:1 main.<async>.<fn>.<async> I understand that the outputted stack trace should include testFunction, but for some reason it isn't. If I do it

Using dart's async with stack_trace's Chain

情到浓时终转凉″ 提交于 2019-12-08 03:28:04
问题 I'm trying to take advantage of the Chain object provided by stack_trace like so: import 'dart:async'; import 'package:stack_trace/stack_trace.dart'; main() async { print('Hello world: ${console_test.calculate()}!'); Chain.capture(() async { try { await testFunction(); } catch(e,st) { print(Trace.format(new Chain.forTrace(st))); } }); } Future testFunction() async { throw new Exception("TEST"); } The output I get is this: Hello world: 42! main.dart 4:1 main.<async>.<fn>.<async> I understand

Stream image file to HttpResponse efficiently

青春壹個敷衍的年華 提交于 2019-12-07 19:13:47
问题 My server-side Dart web app serves image files for certain requests. Simplified, here's what it currently does: HttpServer.bind(InternetAddress.ANY_IP_V4, 80) .then((HttpServer server) { server.listen((HttpRequest request) { request.response.statusCode = HttpStatus.OK; request.response.headers.contentType = ContentType.parse("image/jpg"); var file = new File("C:\\images\\myImage.jpg"); file.readAsBytes().then((List<int> bytes) { bytes.forEach((int b) => request.response.writeCharCode(b)); //

Can I get a “stack trace” that traces all async calls, with Dart?

China☆狼群 提交于 2019-12-07 04:15:10
问题 Consider code like this: import 'dart:async'; foo() { new Timer(onesec, bar); } bar() { throw "from bar"; } const onesec = const Duration(seconds:1); main() { runZoned(() { new Timer(onesec, foo); }, onError: (e, stackTrace) => print(stackTrace)); } How can I tell that bar was "called" by foo in the stackTrace that I print out? I'd like to see something like: bar ... foo ... main 回答1: Have a look at the stack_trace package. It uses zones to keep track of asynchronous callbacks. Capturing

Stream image file to HttpResponse efficiently

ぃ、小莉子 提交于 2019-12-06 15:24:00
My server-side Dart web app serves image files for certain requests. Simplified, here's what it currently does: HttpServer.bind(InternetAddress.ANY_IP_V4, 80) .then((HttpServer server) { server.listen((HttpRequest request) { request.response.statusCode = HttpStatus.OK; request.response.headers.contentType = ContentType.parse("image/jpg"); var file = new File("C:\\images\\myImage.jpg"); file.readAsBytes().then((List<int> bytes) { bytes.forEach((int b) => request.response.writeCharCode(b)); // slow! request.response.close(); }); } } This works, but it's fairly slow and I suspect that writing

setState doesn't update the user interface

╄→尐↘猪︶ㄣ 提交于 2019-12-06 13:56:07
问题 I've been facing some problems related to the setState function while using Stateful Widgets that updates itself with the help of Timers. The code below show 2 main classes that replicate how I came to find this error. The Text Widget "Lorem" should be inserted within 10 seconds - and it is - but it's never shown. I tried to debug the array "Items" and it does contain the "lorem" Text Widget after 5 seconds, as it should. The "build" function runs but doesn't make any difference in the UI.