Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
consumer
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Builder takes three parameters 1. [BuildContext] which is our context
// 2. [Object] it is the object and 3. it is optional [Widget] child
return Consumer(
builder: (context, Counter counter, _) => Scaffold(
appBar: AppBar(
title: Text("Provider Demo"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'${counter.getCounter()}',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FloatingActionButton(
onPressed: counter.increment,
tooltip: 'Increment',
child: Icon(Icons.add),
),
SizedBox(height: 10),
FloatingActionButton(
onPressed: counter.decrement,
tooltip: 'Increment',
child: Icon(Icons.remove),
)
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.