Skip to content

Instantly share code, notes, and snippets.

@itsatifsiddiqui
Created May 10, 2019 11:20
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save itsatifsiddiqui/9c8831814b8612124f9da16bbbdf3148 to your computer and use it in GitHub Desktop.
Save itsatifsiddiqui/9c8831814b8612124f9da16bbbdf3148 to your computer and use it in GitHub Desktop.
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