Created
January 4, 2019 11:11
-
-
Save 9jaswag/69c2179fc3a062eb14954a1ca7f727d9 to your computer and use it in GitHub Desktop.
counter bloc demo
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
import 'package:bloc_counter/counter_provider.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:bloc_counter/counter_bloc.dart'; | |
class Counter extends StatefulWidget { | |
@override | |
_CounterState createState() => _CounterState(); | |
} | |
class _CounterState extends State<Counter> { | |
@override | |
void dispose() { | |
bloc.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return StreamBuilder( | |
stream: bloc.getCount, | |
initialData: CounterProvider().count, | |
builder: (context, snapshot) => Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text( | |
'You have pushed the button this many times:', | |
), | |
Text( | |
'${snapshot.data}', | |
style: Theme.of(context).textTheme.display1, | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment