Skip to content

Instantly share code, notes, and snippets.

@awaik
Created November 13, 2019 16:36
Show Gist options
  • Save awaik/a5848a2450a702c374b73293c2e1d120 to your computer and use it in GitHub Desktop.
Save awaik/a5848a2450a702c374b73293c2e1d120 to your computer and use it in GitHub Desktop.
class MyHomePage extends StatelessWidget {
CounterBloc counterBloc = CounterBloc();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: StreamBuilder<int>(
stream: counterBloc.pressedCount,
builder: (context, snapshot) {
return Text(
'Flutter Counter Bloc Example - ${snapshot.data.toString()}',
);
}),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
StreamBuilder<int>(
stream: counterBloc.pressedCount,
builder: (context, snapshot) {
return Text(
'${snapshot.data.toString()}',
style: Theme.of(context).textTheme.display1,
);
}),
],
),
),
floatingActionButton: Container(
width: 100.0,
height: 100.0,
child: FloatingActionButton(
onPressed: () {
counterBloc.incrementCounter.add(null);
},
tooltip: 'Increment',
child: Text(
"+ \n send \n to BLoC",
textAlign: TextAlign.center,
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment