Created
August 3, 2018 15:40
-
-
Save RedBrogdon/a982e6f896936547ee0af1390e4816b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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