Last active
February 5, 2020 14:10
-
-
Save slamdon/e24f84aac20a8c7d7d74845677e83c55 to your computer and use it in GitHub Desktop.
Tap Counter - StatefulWidget
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 Home extends StatefulWidget { | |
Home({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_HomeState createState() => _HomeState(); | |
} | |
class _HomeState extends State<Home> { | |
int _counter = 0; | |
void _incrementCounter() { | |
// build will be called when we call setState() | |
setState(() { | |
_counter++; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text('Tapped: $_counter', | |
style: TextStyle( | |
fontSize: 28, | |
color: Colors.grey, | |
)), | |
FlatButton( | |
onPressed: _incrementCounter, | |
color: Colors.blueAccent, | |
textColor: Colors.white, | |
child: Text("TAP"), | |
) | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment