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

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.merge([s1, s2]); await for(int val in s3) { print(val); } } Stream<int> stream(int min) async* { int i = min; while(i < min + 10) { yield i++; } } See also http://news.dartlang.org/2016/03/unboxing-packages-async-part-2.html … Read more

Flutter – setState not updating inner Stateful Widget

This should sort your problem out. Basically you always want your Widgets created in your build method hierarchy. import ‘dart:async’; import ‘package:flutter/material.dart’; void main() => runApp(new MaterialApp(home: new Scaffold(body: new MainWidget()))); class MainWidget extends StatefulWidget { @override State createState() => new MainWidgetState(); } class MainWidgetState extends State<MainWidget> { List<ItemData> _data = new List(); Timer timer; … Read more

is there any way to cancel a dart Future?

You can use CancelableOperation or CancelableCompleter to cancel a future. See below the 2 versions: Solution 1: CancelableOperation (included in a test so you can try it yourself): cancel a future test(“CancelableOperation with future”, () async { var cancellableOperation = CancelableOperation.fromFuture( Future.value(‘future result’), onCancel: () => {debugPrint(‘onCancel’)}, ); // cancellableOperation.cancel(); // uncomment this to test … Read more

tech