Skip to content

Instantly share code, notes, and snippets.

@jonahwilliams
Created April 12, 2018 01:39
Show Gist options
  • Save jonahwilliams/e8d71584c54d9c7c2d8dffb21f70d061 to your computer and use it in GitHub Desktop.
Save jonahwilliams/e8d71584c54d9c7c2d8dffb21f70d061 to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
void main() {
final controller = new StreamController(sync: true);
controller.add(2);
new Future.delayed(const Duration(seconds: 1)).then((_) {
controller.add(3);
});
runApp(new MaterialApp(home: new StreamBuilder(
stream: controller.stream,
builder: (context, snapshot) {
if (snapshot.hasData) {
return new Text('${snapshot.data}', textDirection: TextDirection.ltr,);
}
// this is never displayed
return new Text('LOADING', textDirection: TextDirection.ltr,);
})));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment