Skip to content

Instantly share code, notes, and snippets.

@RedBrogdon
Created August 3, 2018 15:40
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RedBrogdon/a982e6f896936547ee0af1390e4816b2 to your computer and use it in GitHub Desktop.
Save RedBrogdon/a982e6f896936547ee0af1390e4816b2 to your computer and use it in GitHub Desktop.
class MyApp extends StatelessWidget {
Stream<int> _countUp() async* {
for (int i = 1; i <= 10; i++) {
yield await Future.delayed(Duration(seconds: 1), () => i);
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Counting with Streams',
home: Scaffold(
appBar: AppBar(
title: Text('Let\'s count!'),
),
body: Center(
child: StreamBuilder<int>(
stream: _countUp(),
builder: (context, snapshot) => Text(
snapshot?.data?.toString() ?? '0',
style: Theme.of(context).textTheme.headline),
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment