From 6e9f4760178ec0da8a1f0b4fb15f2e6cd8698c7c Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Mon, 21 Dec 2020 17:12:12 +0100 Subject: [PATCH] Added leap year instruction page --- lib/main.dart | 3 +- .../instructions/LeapInstructionPage.dart | 133 ++++++++++++++++++ 2 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 lib/pages/practice/instructions/LeapInstructionPage.dart diff --git a/lib/main.dart b/lib/main.dart index a76343f..81166fa 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,6 +7,7 @@ import 'package:ohthatsa/pages/practice/PracticePage.dart'; import 'package:ohthatsa/pages/MonthValuesPage.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; +import 'package:ohthatsa/pages/practice/instructions/LeapInstructionPage.dart'; import 'package:ohthatsa/pages/practice/instructions/MonthInstructionPage.dart'; import 'package:ohthatsa/pages/practice/instructions/YearInstructionPage.dart'; import 'package:ohthatsa/pages/practice/instructions/CenturyInstructionPage.dart'; @@ -140,7 +141,7 @@ class RouteGenerator { return MaterialPageRoute(builder: (context) => CenturyInstructionPage()); } case "/instructions/leap": { - return MaterialPageRoute(builder: (context) => YearInstructionPage()); + return MaterialPageRoute(builder: (context) => LeapInstructionPage()); } case "/instructions/mod": { return MaterialPageRoute(builder: (context) => YearInstructionPage()); diff --git a/lib/pages/practice/instructions/LeapInstructionPage.dart b/lib/pages/practice/instructions/LeapInstructionPage.dart new file mode 100644 index 0000000..1b02e7a --- /dev/null +++ b/lib/pages/practice/instructions/LeapInstructionPage.dart @@ -0,0 +1,133 @@ +import 'package:flutter/material.dart'; +import 'package:numberpicker/numberpicker.dart'; +import 'package:ohthatsa/other/AppDrawer.dart'; +import 'package:ohthatsa/util/DayCalculator.dart'; +import 'package:ohthatsa/util/Months.dart'; + +class LeapInstructionPage extends StatefulWidget { + @override + _LeapInstructionPageState createState() => _LeapInstructionPageState(); +} + +class _LeapInstructionPageState extends State { + int year; + bool isLeapYear; + bool divBy4; + bool divBy100; + bool divBy400; + + @override + void initState(){ + super.initState(); + this.setYear(DateTime.now().year); + } + + void setYear(int newYear){ + year = newYear; + isLeapYear = DayCalculator.isLeapYear(year); + divBy4 = (year % 4) == 0; + divBy100 = (year % 100) == 0; + divBy400 = (year % 400) == 0; + setState(() {}); + } + + static const textStyle = TextStyle( + fontSize: 20 + ); + static const pageNum = TextStyle( + color: Colors.grey, + fontSize: 20 + ); + static const pageNumCurrent = TextStyle( + color: Colors.blue, + fontSize: 20 + ); + @override + Widget build(BuildContext context){ + return Scaffold( + drawer: AppDrawer(), + appBar: AppBar( + title: Text("Leap Year Instructions") + ), + + body: PageView( + children: [ + Container( + padding: EdgeInsets.fromLTRB(0, 50, 0, 10), + child:Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("A year is a leap year if...", style: textStyle), + Text("It is divisible by 4, unless...", style: textStyle), + Text("It's also divisible by 100, unless...", style: textStyle), + Text("It's divisible by 400", style: textStyle), + Spacer(), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("1", style: pageNumCurrent), + Text(" - ", style: pageNum), + Text("2", style: pageNum), + ], + ) + ] + ) + ), + Container( + padding: EdgeInsets.fromLTRB(0, 50, 0, 10), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + NumberPicker.integer( + initialValue: year, + minValue: 0, + maxValue: 10000, + onChanged: (newYear) => { this.setYear(newYear) } + ), + Visibility( + visible: divBy4, + child: Text(year.toString() + " is divisible by 4", style: textStyle) + ), + Visibility( + visible: divBy100, + child: Column( + children: [ + Text("But...", style: textStyle), + Text(year.toString() + " is also divisible by 100", style: textStyle) + ], + ) + ), + Visibility( + visible: divBy400, + child: Column( + children: [ + Text("But...", style: textStyle), + Text(year.toString() + " is also divisible by 400", style: textStyle) + ], + ) + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("So " + year.toString() + " is", style: textStyle), + Text(this.isLeapYear ? " " : " not ", style: textStyle), + Text("a leap year", style: textStyle) + ], + ), + Spacer(), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("1", style: pageNum), + Text(" - ", style: pageNum), + Text("2", style: pageNumCurrent), + ], + ) + ], + ) + ) + ] + ) + ); + } +} \ No newline at end of file