Skip to content

Commit

Permalink
Fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
filiph committed Apr 9, 2018
1 parent 075a120 commit 95e836a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions hello_world/lib/main.dart
Expand Up @@ -24,9 +24,15 @@ class MyHomePage extends StatefulWidget {
_MyHomePageState createState() => new _MyHomePageState();
}

int _counter = 0;

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

void _increment() {
setState(() {
_counter += 1;
});
}

@override
Widget build(BuildContext context) {
return new Scaffold(
Expand All @@ -47,12 +53,16 @@ class _MyHomePageState extends State<MyHomePage> {
],
),
),
floatingActionButton: new Incrementer(),
floatingActionButton: new Incrementer(_increment),
);
}
}

class Incrementer extends StatefulWidget {
final Function increment;

Incrementer(this.increment);

@override
IncrementerState createState() {
return new IncrementerState();
Expand All @@ -63,9 +73,7 @@ class IncrementerState extends State<Incrementer> {
@override
Widget build(BuildContext context) {
return new FloatingActionButton(
onPressed: () => setState(() {
_counter += 1;
}),
onPressed: widget.increment,
tooltip: 'Increment',
child: new Icon(Icons.add),
);
Expand Down

0 comments on commit 95e836a

Please sign in to comment.