Created
May 10, 2019 11:20
-
-
Save itsatifsiddiqui/9c8831814b8612124f9da16bbbdf3148 to your computer and use it in GitHub Desktop.
consumer
This file contains 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
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