diff --git a/weekly_assignment_1/lib/main.dart b/weekly_assignment_1/lib/main.dart index e016029..b9e225b 100644 --- a/weekly_assignment_1/lib/main.dart +++ b/weekly_assignment_1/lib/main.dart @@ -49,6 +49,8 @@ class MyHomePage extends StatefulWidget { class _MyHomePageState extends State { int _counter = 0; + bool displayFizz = false; + bool displayBuzz = false; void _incrementCounter() { setState(() { @@ -61,6 +63,27 @@ class _MyHomePageState extends State { }); } + void _decrementCounter() { + setState(() { + // This call to setState tells the Flutter framework that something has + // changed in this State, which causes it to rerun the build method below + // so that the display can reflect the updated values. If we changed + // _counter without calling setState(), then the build method would not be + // called again, and so nothing would appear to happen. + _counter--; + }); + } + void _zero() { + setState(() { + // This call to setState tells the Flutter framework that something has + // changed in this State, which causes it to rerun the build method below + // so that the display can reflect the updated values. If we changed + // _counter without calling setState(), then the build method would not be + // called again, and so nothing would appear to happen. + _counter = 0; + }); + } + @override Widget build(BuildContext context) { // This method is rerun every time setState is called, for instance as done @@ -102,6 +125,20 @@ class _MyHomePageState extends State { '$_counter', style: Theme.of(context).textTheme.headline4, ), + if (_counter % 3 == 0 && _counter % 5 == 0) Text("fizzbuzz") + else if (_counter % 3 == 0) Text("fizz") + else if (_counter % 5 == 0) Text("buzz"), + FloatingActionButton( + onPressed: _decrementCounter, + tooltip: 'Decrement', + child: const Icon(Icons.remove), + ), + FloatingActionButton( + onPressed: _zero, + tooltip: 'reset', + child: const Icon(Icons.exposure_zero), + ), + ], ), ),