Skip to content

Instantly share code, notes, and snippets.

@slamdon
Last active February 5, 2020 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slamdon/e24f84aac20a8c7d7d74845677e83c55 to your computer and use it in GitHub Desktop.
Save slamdon/e24f84aac20a8c7d7d74845677e83c55 to your computer and use it in GitHub Desktop.
Tap Counter - StatefulWidget
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