From 42d90c00cc7a5ad30086a7f3ec62319a945a2f17 Mon Sep 17 00:00:00 2001 From: Seth Ladd Date: Tue, 12 Jan 2016 10:28:40 -0800 Subject: [PATCH] starter app now has a button that does something --- .../flutter_tools/lib/src/commands/init.dart | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/init.dart b/packages/flutter_tools/lib/src/commands/init.dart index 90bb15148d..e4085940b1 100644 --- a/packages/flutter_tools/lib/src/commands/init.dart +++ b/packages/flutter_tools/lib/src/commands/init.dart @@ -201,14 +201,27 @@ void main() { runApp( new MaterialApp( title: "Flutter Demo", - routes: { + routes: { '/': (RouteArguments args) => new FlutterDemo() } ) ); } -class FlutterDemo extends StatelessComponent { +class FlutterDemo extends StatefulComponent { + @override + State createState() => new FlutterDemoState(); +} + +class FlutterDemoState extends State { + int counter = 0; + + void incrementCounter() { + setState(() { + counter++; + }); + } + Widget build(BuildContext context) { return new Scaffold( toolBar: new ToolBar( @@ -216,13 +229,14 @@ class FlutterDemo extends StatelessComponent { ), body: new Material( child: new Center( - child: new Text("Hello world!") + child: new Text("Button tapped $counter times.") ) ), floatingActionButton: new FloatingActionButton( child: new Icon( icon: 'content/add' - ) + ), + onPressed: incrementCounter ) ); }