Skip to content

Instantly share code, notes, and snippets.

@BouweCeunen
Last active July 19, 2020 11:00
Show Gist options
  • Save BouweCeunen/e07b638990cf073e87a2bc1b01c230ab to your computer and use it in GitHub Desktop.
Save BouweCeunen/e07b638990cf073e87a2bc1b01c230ab to your computer and use it in GitHub Desktop.
StreamController<String> _accountController = new StreamController();
@override
void initState() {
super.initState();
Future<void>.delayed(
Duration(seconds: 2),
() => _accountController.add('Data Loaded'),
);
}
Widget build(BuildContext context) {
return Container(
child: StreamBuilder<String>(
stream: _accountController.stream,
builder: (context, snapshot) {
if (snapshot.hasError) {
return Center(child: Text(snapshot.error.toString()));
}
if (snapshot.hasData) {
return Center(child: Text(snapshot.data));
}
return CircularProgressIndicator();
},
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment