Skip to content

assignment one finished #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions weekly_assignment_1/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class MyHomePage extends StatefulWidget {

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
bool displayFizz = false;
bool displayBuzz = false;

void _incrementCounter() {
setState(() {
Expand All @@ -61,6 +63,27 @@ class _MyHomePageState extends State<MyHomePage> {
});
}

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
Expand Down Expand Up @@ -102,6 +125,20 @@ class _MyHomePageState extends State<MyHomePage> {
'$_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),
),

],
),
),
Expand Down