caching the values used in the year value instruction instead of calculating them throughout the structure
This commit is contained in:
parent
9cb6f6b9fb
commit
de660cf501
1 changed files with 35 additions and 12 deletions
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:numberpicker/numberpicker.dart';
|
import 'package:numberpicker/numberpicker.dart';
|
||||||
|
|
||||||
import 'package:ohthatsa/other/AppDrawer.dart';
|
import 'package:ohthatsa/other/AppDrawer.dart';
|
||||||
|
import 'package:ohthatsa/util/DayCalculator.dart';
|
||||||
import 'package:ohthatsa/util/Months.dart';
|
import 'package:ohthatsa/util/Months.dart';
|
||||||
|
|
||||||
class MonthValuesPage extends StatefulWidget {
|
class MonthValuesPage extends StatefulWidget {
|
||||||
|
@ -11,7 +12,30 @@ class MonthValuesPage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MonthValuesState extends State<MonthValuesPage> {
|
class _MonthValuesState extends State<MonthValuesPage> {
|
||||||
int year = DateTime.now().year;
|
int year;
|
||||||
|
int yy;
|
||||||
|
String centuriesString;
|
||||||
|
String yyString;
|
||||||
|
double yyDiv4;
|
||||||
|
int yyDiv4Floored;
|
||||||
|
int yearValue;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState(){
|
||||||
|
super.initState();
|
||||||
|
this.setYearValues(DateTime.now().year);
|
||||||
|
}
|
||||||
|
void setYearValues(newYear){
|
||||||
|
year = newYear;
|
||||||
|
yy = year % 100;
|
||||||
|
centuriesString = (year ~/ 100).toString();
|
||||||
|
yyString = year.toString().substring(2);
|
||||||
|
yyDiv4 = yy / 4;
|
||||||
|
yyDiv4Floored = yyDiv4.floor();
|
||||||
|
yearValue = DayCalculator.getYearValue(year);
|
||||||
|
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
static const formulaStyle = TextStyle(
|
static const formulaStyle = TextStyle(
|
||||||
fontSize: 20
|
fontSize: 20
|
||||||
);
|
);
|
||||||
|
@ -122,14 +146,13 @@ class _MonthValuesState extends State<MonthValuesPage> {
|
||||||
initialValue: year,
|
initialValue: year,
|
||||||
minValue: 1700,
|
minValue: 1700,
|
||||||
maxValue: 2399,
|
maxValue: 2399,
|
||||||
onChanged: (newYear) =>
|
onChanged: (newYear) => this.setYearValues(newYear)
|
||||||
setState(() => year = newYear),
|
|
||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text("With ", style: formulaStyle),
|
Text("With ", style: formulaStyle),
|
||||||
Text((year / 100).floor().toString(), style: formulaStyle),
|
Text(centuriesString, style: formulaStyle),
|
||||||
Text(year.toString().substring(2), style: YYStyle),
|
Text(year.toString().substring(2), style: YYStyle),
|
||||||
Text(" our formula becomes: ", style: formulaStyle),
|
Text(" our formula becomes: ", style: formulaStyle),
|
||||||
],
|
],
|
||||||
|
@ -138,9 +161,9 @@ class _MonthValuesState extends State<MonthValuesPage> {
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text("(", style: formulaStyle),
|
Text("(", style: formulaStyle),
|
||||||
Text(year.toString().substring(2), style: YYStyle),
|
Text(yyString, style: YYStyle),
|
||||||
Text(" + floor(", style: formulaStyle),
|
Text(" + floor(", style: formulaStyle),
|
||||||
Text(year.toString().substring(2), style: YYStyleU),
|
Text(yyString, style: YYStyleU),
|
||||||
Text(" / 4", style: formulaStyleU),
|
Text(" / 4", style: formulaStyleU),
|
||||||
Text(")) % 7", style: formulaStyle),
|
Text(")) % 7", style: formulaStyle),
|
||||||
],
|
],
|
||||||
|
@ -150,9 +173,9 @@ class _MonthValuesState extends State<MonthValuesPage> {
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text("(", style: formulaStyle),
|
Text("(", style: formulaStyle),
|
||||||
Text(year.toString().substring(2), style: YYStyle),
|
Text(yyString, style: YYStyle),
|
||||||
Text(" + ", style: formulaStyle),
|
Text(" + ", style: formulaStyle),
|
||||||
Text("floor(" + ((year % 100) / 4).toString() + ")", style: formulaStyleU),
|
Text("floor(" + yyDiv4.toString() + ")", style: formulaStyleU),
|
||||||
Text(") % 7", style: formulaStyle),
|
Text(") % 7", style: formulaStyle),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -161,8 +184,8 @@ class _MonthValuesState extends State<MonthValuesPage> {
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text("(", style: formulaStyleU),
|
Text("(", style: formulaStyleU),
|
||||||
Text(year.toString().substring(2), style: YYStyleU),
|
Text(yyString, style: YYStyleU),
|
||||||
Text(" + " + ((year % 100) / 4).floor().toString() + ")", style: formulaStyleU),
|
Text(" + " + yyDiv4Floored.toString() + ")", style: formulaStyleU),
|
||||||
Text(" % 7", style: formulaStyle),
|
Text(" % 7", style: formulaStyle),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -170,7 +193,7 @@ class _MonthValuesState extends State<MonthValuesPage> {
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text(((year % 100) + ((year % 100) / 4).floor()).toString(), style: formulaStyleU),
|
Text((yy + yyDiv4Floored).toString(), style: formulaStyleU),
|
||||||
Text(" % 7", style: formulaStyleU),
|
Text(" % 7", style: formulaStyleU),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -179,7 +202,7 @@ class _MonthValuesState extends State<MonthValuesPage> {
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text("So the year value of " + year.toString() + " is: ", style: formulaStyle),
|
Text("So the year value of " + year.toString() + " is: ", style: formulaStyle),
|
||||||
Text((((year % 100) + ((year % 100) / 4).floor()) % 7).toString(), style: formulaStyleU),
|
Text(yearValue.toString(), style: formulaStyleU),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Spacer(),
|
Spacer(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue