Skip to content

Instantly share code, notes, and snippets.

@r3dm1ke
Created June 2, 2020 21:05
Show Gist options
  • Save r3dm1ke/749d98084ca11d63d10c483729840883 to your computer and use it in GitHub Desktop.
Save r3dm1ke/749d98084ca11d63d10c483729840883 to your computer and use it in GitHub Desktop.
class CounterPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final CounterBloc counterBloc = BlocProvider.of<CounterBloc>(context);
return Scaffold(
appBar: AppBar(title: Text('BLoC Demo')),
body: BlocBuilder<CounterBloc, int>(builder: (context, count) {
return Center(
child:
Column(mainAxisAlignment: MainAxisAlignment.center, children: [
Text('$count', style: TextStyle(fontSize: 32.0)),
RaisedButton(
child: Icon(Icons.add),
onPressed: () {
counterBloc.add(CounterEvent.increment);
}),
RaisedButton(
child: Icon(Icons.remove),
onPressed: () {
counterBloc.add(CounterEvent.decrement);
})
]));
}),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment