dart-async

How to implement persistent stopwatch in Flutter?

橙三吉。 提交于 2019-12-05 06:26:30
问题 I am implementing a timer in flutter .Here is the structure of the app. Page A (Contains some lists where user clicks and takes it to timer Page). Page B formats ,runs the timer .I am able to run the timer/stopwatch properly,but when i press the back button on Page B I get the setstate() called after dispose error.I understand that this is the expected behaviour. If i use timer.cancel() on dispose I wont be getting the error ,but the timer will stop running.The timer/stopwatch should continue

setState doesn't update the user interface

情到浓时终转凉″ 提交于 2019-12-04 19:49:54
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. class textList extends StatefulWidget { @override State<StatefulWidget> createState() => new

How can I execute two dart code in one HTML

坚强是说给别人听的谎言 提交于 2019-12-03 16:27:30
I'm trying to build an Dart App. This is the process that I would like to have. At the first connection, the user have a loading page. During this time, he has an animation, and in background, the big dart file is downloaded (came from dart2js for dart). Once it's over, the downloaded script is execute and the app cans start to work. Any idea about the possibility of this process ? Thank you. EDIT: import "dart:async"; @lazy import 'test.dart' as foo; const lazy = const DeferredLibrary('test'); void main() { foo.init(); // Supposed to throw a NoSuchMethodError. lazy.load().then(onFooLoaded); }

How to use `expectAsync2` correctly when writing dart unittest?

半城伤御伤魂 提交于 2019-12-02 03:00:56
问题 I was trying this method expectAsync2 , so there was this question: Why the async test passed, but there are some error messages displayed? But it seems I didn't use it correctly. Is there any good example of expectAsync2 ? 回答1: In the referenced question expectAsync was just used to guard a async call so that the test doesn't end before the call of new Timer(...) finishes. You can additionally add provide how often (min/max) the method has to be called to satisfy the test. If your tested

How to use `expectAsync2` correctly when writing dart unittest?

浪尽此生 提交于 2019-12-02 02:38:25
I was trying this method expectAsync2 , so there was this question: Why the async test passed, but there are some error messages displayed? But it seems I didn't use it correctly. Is there any good example of expectAsync2 ? Günter Zöchbauer In the referenced question expectAsync was just used to guard a async call so that the test doesn't end before the call of new Timer(...) finishes. You can additionally add provide how often (min/max) the method has to be called to satisfy the test. If your tested functionality calls a method with more than one parameter you use `expectAsync2) The mistake

Waiting for Futures raised by other Futures

你离开我真会死。 提交于 2019-12-01 22:06:42
I'm using the Lawndart library to access browser data, and want to collect the results of a set of queries. Here's what I thought should work: numberOfRecordsPerSection(callback) { var map = new Map(); db_sections.keys().forEach((_key) { db_sections.getByKey(_key).then((Map _section) { int count = _section.length; map[_key] = count; }); }).then(callback(map)); } However, when the callback is called, map is still empty (it gets populated correctly, but later, after all the Futures have completed). I assume the problem is that the Futures created by the getByKey() calls are not "captured by" the

Dart language support async/await programming style, or similar? [duplicate]

隐身守侯 提交于 2019-12-01 16:58:47
This question already has an answer here: Async/Await feature in Dart 1.8 1 answer It is possible write similar code in Dart language? int i; try { i = await getResultAsync(); } catch(exception) { // Do something } Basic support is already available. See https://www.dartlang.org/articles/await-async/ for more details. main() async { print(await foo()); try { print(await fooThrows()); } catch(e) { print(e); } } foo() async => 42; fooThrows() async => throw 'Anything'; Not for now. See issue Support for "await" in Dart . 来源: https://stackoverflow.com/questions/17490888/dart-language-support

How to catch all uncaught errors in a dart polymer app?

天大地大妈咪最大 提交于 2019-11-29 15:39:24
I want to put in a handler that will catch all unhandled errors in a Polymer app. I figured Zone would be the trick so tried void main() { runZoned(() => initPolymer(), onError: (e, stackTrace) { _log.shout('TOP ZONE', e, stackTrace); }); } But that doesn't work. The errors never get to this error handler. Not sure if this relates to http://code.google.com/p/dart/issues/detail?id=15854 How do people handle this? How about using Window.onError . import 'dart:html'; main() { window.onError.listen((ErrorEvent e) => print(e.message)); throw 'boom!'; } So I know we have gotten error handling to

How to catch all uncaught errors in a dart polymer app?

亡梦爱人 提交于 2019-11-28 10:50:04
问题 I want to put in a handler that will catch all unhandled errors in a Polymer app. I figured Zone would be the trick so tried void main() { runZoned(() => initPolymer(), onError: (e, stackTrace) { _log.shout('TOP ZONE', e, stackTrace); }); } But that doesn't work. The errors never get to this error handler. Not sure if this relates to http://code.google.com/p/dart/issues/detail?id=15854 How do people handle this? 回答1: How about using Window.onError. import 'dart:html'; main() { window.onError

How can I merge multiple Streams into a higher level Stream?

久未见 提交于 2019-11-28 09:58:50
I have two streams, Stream<A> and Stream<B> . I have a constructor for a type C that takes an A and a B . How do I merge the two Stream s into a Stream<C> ? You can use StreamZip in package:async to combine two streams into one stream of pairs, then create the C objects from that. import "package:async" show StreamZip; ... Stream<C> createCs(Stream<A> as, Stream<B> bs) => new StreamZip([as, bs]).map((ab) => new C(ab[0], ab[1])); import 'dart:async' show Stream; import 'package:async/async.dart' show StreamGroup; main() async { var s1 = stream(10); var s2 = stream(20); var s3 = StreamGroup