From 077e2d15c693e19827814a87c92cd631c5666798 Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Wed, 30 Dec 2020 16:30:11 +0100 Subject: [PATCH] Switched to custom "Text" classes for different text, cleaner but not sure if 'the way' --- lib/pages/practice/PracticePage.dart | 22 +-- lib/pages/practice/PracticeSetupPage.dart | 11 +- .../instructions/AllInstructionPage.dart | 48 +++---- .../instructions/LeapInstructionPage.dart | 49 +++---- .../instructions/ModInstructionPage.dart | 28 ++-- .../instructions/YearInstructionPage.dart | 132 ++++++------------ lib/util/TextStyles.dart | 51 +++++++ 7 files changed, 145 insertions(+), 196 deletions(-) create mode 100644 lib/util/TextStyles.dart diff --git a/lib/pages/practice/PracticePage.dart b/lib/pages/practice/PracticePage.dart index 35b4cb9..0aedcd6 100644 --- a/lib/pages/practice/PracticePage.dart +++ b/lib/pages/practice/PracticePage.dart @@ -10,6 +10,7 @@ import 'package:ohthatsa/pages/practice/thing/PracticeThingMonth.dart'; import 'package:ohthatsa/other/AppDrawer.dart'; import 'package:ohthatsa/pages/practice/PracticeType.dart'; import 'package:ohthatsa/pages/practice/thing/PracticeThingYear.dart'; +import 'package:ohthatsa/util/TextStyles.dart'; class PracticePage extends StatefulWidget { @@ -137,24 +138,9 @@ class PracticePageState extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( - "Correct: " + _correct.toString(), - style: TextStyle( - fontSize: 20, - ) - ), - Text( - (_startCount - _count).toString() + " Left", - style: TextStyle( - fontSize: 20, - ) - ), - Text( - "Incorrect: " + _incorrect.toString(), - style: TextStyle( - fontSize: 20, - ) - ) + Text20("Correct: " + _correct.toString()), + Text20((_startCount - _count).toString() + " Left"), + Text20("Incorrect: " + _incorrect.toString()), ], ), Column( diff --git a/lib/pages/practice/PracticeSetupPage.dart b/lib/pages/practice/PracticeSetupPage.dart index b37f4eb..72a7b62 100644 --- a/lib/pages/practice/PracticeSetupPage.dart +++ b/lib/pages/practice/PracticeSetupPage.dart @@ -5,6 +5,7 @@ import 'package:ohthatsa/pages/practice/PracticeDatabase.dart'; import 'package:ohthatsa/pages/practice/PracticeSetup.dart'; import 'package:ohthatsa/pages/practice/PracticeType.dart'; import 'package:ohthatsa/util/Extensions.dart'; +import 'package:ohthatsa/util/TextStyles.dart'; import 'instructions/MonthInstructionPage.dart'; @@ -89,10 +90,7 @@ class _PracticeSetupState extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( - "How many rounds", - style: TextStyle(fontSize: 20), - ), + Text20("How many rounds"), NumberPicker.horizontal( initialValue: _count, minValue: 1, @@ -103,10 +101,7 @@ class _PracticeSetupState extends State { ] ), CheckboxListTile( - title: Text( - "Show correct Answer", - style: TextStyle(fontSize: 20) - ), + title: Text20("Show correct Answer"), value: _showCorrect, onChanged: (value) { setState(() { diff --git a/lib/pages/practice/instructions/AllInstructionPage.dart b/lib/pages/practice/instructions/AllInstructionPage.dart index 5cd482a..ef60882 100644 --- a/lib/pages/practice/instructions/AllInstructionPage.dart +++ b/lib/pages/practice/instructions/AllInstructionPage.dart @@ -3,6 +3,7 @@ import 'package:numberpicker/numberpicker.dart'; import 'package:ohthatsa/other/AppDrawer.dart'; import 'package:ohthatsa/util/DayCalculator.dart'; import 'package:ohthatsa/util/Months.dart'; +import 'package:ohthatsa/util/TextStyles.dart'; class AllInstructionPage extends StatefulWidget { @override @@ -16,17 +17,6 @@ class _AllInstructionPageState extends State { super.initState(); } - static const textStyle = TextStyle( - fontSize: 20 - ); - static const textStyleU = TextStyle( - fontSize: 20, - decoration: TextDecoration.underline - ); - static const valueStyle = TextStyle( - color: Colors.green, - fontSize: 20 - ); static const daysOfTheWeek = [ "Sunday", "Monday", @@ -52,22 +42,22 @@ class _AllInstructionPageState extends State { child:Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text("To calculate the weekday", style: textStyle), - Text("Add all the values together:", style: textStyle), - Text("Day of the Month", style: textStyle), - Text("+", style: TextStyle(fontSize: 15)), - Text("Month Value", style: textStyle), - Text("+", style: TextStyle(fontSize: 15)), - Text("Year Value", style: textStyle), - Text("+", style: TextStyle(fontSize: 15)), - Text("Century Value", style: textStyle), - Text("-", style: TextStyle(fontSize: 15)), - Text("Leap Value (1 or 0)", style: textStyle), - Text("(if in January/February)", style: TextStyle(fontSize: 15)), - Text("", style: TextStyle(fontSize: 15)), - Text("Mod the result by 7", style: textStyle), - Text("", style: TextStyle(fontSize: 15)), - Text("And check what day it is:", style: textStyle), + Text20("To calculate the weekday"), + Text20("Add all the values together:"), + Text20("Day of the Month"), + Text15("+"), + Text20("Month Value"), + Text15("+"), + Text20("Year Value"), + Text15("+"), + Text20("Century Value"), + Text15("-"), + Text20("Leap Value (1 or 0)"), + Text15("(if in January/February)"), + Text15(""), + Text20("Mod the result by 7"), + Text15(""), + Text20("And check what day it is:"), Table( children: List.generate(daysOfTheWeek.length, (i) => TableRow( @@ -76,14 +66,14 @@ class _AllInstructionPageState extends State { child: Text( daysOfTheWeek[i], textAlign: TextAlign.right, - style: TextStyle(fontSize: 20) + style: TextStyles.textStyle20 ) ), TableCell( child: Text( i.toString(), textAlign: TextAlign.center, - style: TextStyle(fontSize: 20) + style: TextStyles.textStyle20 ) ) ] diff --git a/lib/pages/practice/instructions/LeapInstructionPage.dart b/lib/pages/practice/instructions/LeapInstructionPage.dart index 1b02e7a..5346c4b 100644 --- a/lib/pages/practice/instructions/LeapInstructionPage.dart +++ b/lib/pages/practice/instructions/LeapInstructionPage.dart @@ -2,7 +2,7 @@ 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'; +import 'package:ohthatsa/util/TextStyles.dart'; class LeapInstructionPage extends StatefulWidget { @override @@ -31,17 +31,6 @@ class _LeapInstructionPageState extends State { 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( @@ -57,17 +46,17 @@ class _LeapInstructionPageState extends State { 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), + Text20("A year is a leap year if..."), + Text20("It is divisible by 4, unless..."), + Text20("It's also divisible by 100, unless..."), + Text20("It's divisible by 400"), Spacer(), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text("1", style: pageNumCurrent), - Text(" - ", style: pageNum), - Text("2", style: pageNum), + Text("1", style: TextStyles.textStyle20.apply(color: Colors.blue)), + Text(" - ", style: TextStyles.textStyle20.apply(color: Colors.grey)), + Text("2", style: TextStyles.textStyle20.apply(color: Colors.grey)), ], ) ] @@ -86,14 +75,14 @@ class _LeapInstructionPageState extends State { ), Visibility( visible: divBy4, - child: Text(year.toString() + " is divisible by 4", style: textStyle) + child: Text20(year.toString() + " is divisible by 4") ), Visibility( visible: divBy100, child: Column( children: [ - Text("But...", style: textStyle), - Text(year.toString() + " is also divisible by 100", style: textStyle) + Text20("But..."), + Text20(year.toString() + " is also divisible by 100") ], ) ), @@ -101,26 +90,26 @@ class _LeapInstructionPageState extends State { visible: divBy400, child: Column( children: [ - Text("But...", style: textStyle), - Text(year.toString() + " is also divisible by 400", style: textStyle) + Text20("But..."), + Text20(year.toString() + " is also divisible by 400") ], ) ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text("So " + year.toString() + " is", style: textStyle), - Text(this.isLeapYear ? " " : " not ", style: textStyle), - Text("a leap year", style: textStyle) + Text20("So " + year.toString() + " is"), + Text20(this.isLeapYear ? " " : " not "), + Text20("a leap year") ], ), Spacer(), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text("1", style: pageNum), - Text(" - ", style: pageNum), - Text("2", style: pageNumCurrent), + Text("1", style: TextStyles.textStyle20.apply(color: Colors.grey)), + Text(" - ", style: TextStyles.textStyle20.apply(color: Colors.grey)), + Text("2", style: TextStyles.textStyle20.apply(color: Colors.blue)), ], ) ], diff --git a/lib/pages/practice/instructions/ModInstructionPage.dart b/lib/pages/practice/instructions/ModInstructionPage.dart index 156cbbd..1f7aa7a 100644 --- a/lib/pages/practice/instructions/ModInstructionPage.dart +++ b/lib/pages/practice/instructions/ModInstructionPage.dart @@ -3,6 +3,7 @@ import 'package:numberpicker/numberpicker.dart'; import 'package:ohthatsa/other/AppDrawer.dart'; import 'package:ohthatsa/util/DayCalculator.dart'; import 'package:ohthatsa/util/Months.dart'; +import 'package:ohthatsa/util/TextStyles.dart'; class ModInstructionPage extends StatefulWidget { @override @@ -27,17 +28,6 @@ class _ModInstructionPageState extends State { setState(() {}); } - static const textStyle = TextStyle( - fontSize: 20 - ); - static const textStyleU = TextStyle( - fontSize: 20, - decoration: TextDecoration.underline - ); - static const valueStyle = TextStyle( - color: Colors.green, - fontSize: 20 - ); @override Widget build(BuildContext context){ return Scaffold( @@ -53,7 +43,7 @@ class _ModInstructionPageState extends State { child:Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text("Modulus (Mod) is the remainder after dividing", style: textStyle), + Text20("Modulus (Mod) is the remainder after dividing"), NumberPicker.integer( initialValue: value, minValue: 0, @@ -63,18 +53,18 @@ class _ModInstructionPageState extends State { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text(value.toString(), style: valueStyle), - Text(" divided by 7 is " + div.toString(), style: textStyle), + Text(value.toString(), style: TextStyles.textStyle20.apply(color: Colors.green)), + Text20(" divided by 7 is " + div.toString()), ], ), - Text("But that leaves " + remainder.toString() + " left over", style: textStyle), + Text20("But that leaves " + remainder.toString() + " left over"), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text("So the result of ", style: textStyle), - Text(value.toString(), style: valueStyle), - Text(" mod 7 is ", style: textStyle), - Text(remainder.toString(), style: textStyleU), + Text20("So the result of "), + Text(value.toString(), style: TextStyles.textStyle20.apply(color: Colors.green)), + Text20(" mod 7 is "), + Text(remainder.toString(), style: TextStyles.textStyle20.apply(decoration: TextDecoration.underline)), ], ), ] diff --git a/lib/pages/practice/instructions/YearInstructionPage.dart b/lib/pages/practice/instructions/YearInstructionPage.dart index a72cc39..2ee7149 100644 --- a/lib/pages/practice/instructions/YearInstructionPage.dart +++ b/lib/pages/practice/instructions/YearInstructionPage.dart @@ -4,6 +4,7 @@ import 'package:numberpicker/numberpicker.dart'; import 'package:ohthatsa/other/AppDrawer.dart'; import 'package:ohthatsa/util/DayCalculator.dart'; +import 'package:ohthatsa/util/TextStyles.dart'; import 'package:term_glyph/term_glyph.dart' as glyph; class YearInstructionPage extends StatefulWidget { @@ -36,30 +37,7 @@ class _YearInstructionPageState extends State { setState(() {}); } - static const formulaStyle = TextStyle( - fontSize: 20 - ); - static const formulaStyleU = TextStyle( - fontSize: 20, - decoration: TextDecoration.underline - ); - static const YYStyle = TextStyle( - color: Colors.green, - fontSize: 20 - ); - static const YYStyleU = TextStyle( - color: Colors.green, - fontSize: 20, - decoration: TextDecoration.underline - ); - 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( @@ -75,62 +53,32 @@ class _YearInstructionPageState extends State { mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ - Text( - "Take only the last two digits: ", - style: TextStyle(fontSize: 25) - ), + Text20("Take only the last two digits: "), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text( - "YY", - style: TextStyle( - color: Colors.grey, - fontSize: 25 - ) - ), - Text( - "YY", - style: YYStyle - ) + Text("YY", style: TextStyles.textStyle20.apply(color: Colors.grey)), + Text("YY", style: TextStyles.textStyle20.apply(color: Colors.green)), ], ), - Text( - "Calculate:", - style: TextStyle(fontSize: 25) - ), + Text20("Calculate:"), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text( - "(", - style: formulaStyle, - ), - Text( - "YY", - style: YYStyle - ), - Text( - " + floor(", - style: formulaStyle - ), - Text( - "YY", - style: YYStyle - ), - Text( - " / 4)) % 7", - style: formulaStyle - ), + Text20("("), + Text("YY", style: TextStyles.textStyle20.apply(color: Colors.green)), + Text20(" + floor("), + Text("YY", style: TextStyles.textStyle20.apply(color: Colors.green)), + Text20(" / 4)) % 7"), ], ), Spacer(), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text("1", style: pageNumCurrent), - Text(" - ", style: pageNum), - Text("2", style: pageNum), + Text("1", style: TextStyles.textStyle20.apply(color: Colors.blue)), + Text(" - ", style: TextStyles.textStyle20.apply(color: Colors.grey)), + Text("2", style: TextStyles.textStyle20.apply(color: Colors.grey)), ], ) ], @@ -151,67 +99,67 @@ class _YearInstructionPageState extends State { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text("For ", style: formulaStyle), - Text(centuriesString, style: formulaStyle), - Text(year.toString().substring(2), style: YYStyle), - Text(" our formula becomes: ", style: formulaStyle), + Text20("For "), + Text20(centuriesString), + Text(year.toString().substring(2), style: TextStyles.textStyle20.apply(color: Colors.green)), + Text20(" our formula becomes: "), ], ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text("(", style: formulaStyle), - Text(yyString, style: YYStyle), - Text(" + floor(", style: formulaStyle), - Text(yyString, style: YYStyleU), - Text(" / 4", style: formulaStyleU), - Text(")) % 7", style: formulaStyle), + Text20("("), + Text(yyString, style: TextStyles.textStyle20.apply(color: Colors.green)), + Text20(" + floor("), + Text(yyString, style: TextStyles.textStyle20u.apply(color: Colors.green)), + Text20u(" / 4"), + Text20(")) % 7"), ], ), Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text("(", style: formulaStyle), - Text(yyString, style: YYStyle), - Text(" + ", style: formulaStyle), - Text("floor(" + yyDiv4.toString() + ")", style: formulaStyleU), - Text(") % 7", style: formulaStyle), + Text20("("), + Text(yyString, style: TextStyles.textStyle20u.apply(color: Colors.green)), + Text20(" + "), + Text20u("floor(" + yyDiv4.toString() + ")"), + Text20(") % 7"), ], ), Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text("(", style: formulaStyleU), - Text(yyString, style: YYStyleU), - Text(" + " + yyDiv4Floored.toString() + ")", style: formulaStyleU), - Text(" % 7", style: formulaStyle), + Text20u("("), + Text(yyString, style: TextStyles.textStyle20u.apply(color: Colors.green)), + Text20u(" + " + yyDiv4Floored.toString() + ")"), + Text20u(" % 7"), ], ), Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text((yy + yyDiv4Floored).toString(), style: formulaStyleU), - Text(" % 7", style: formulaStyleU), + Text20u((yy + yyDiv4Floored).toString()), + Text20u(" % 7"), ], ), Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text("So the year value of " + year.toString() + " is: ", style: formulaStyle), - Text(yearValue.toString(), style: formulaStyleU), + Text20("So the year value of " + year.toString() + " is: "), + Text20u(yearValue.toString()), ], ), Spacer(), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text("1", style: pageNum), - Text(" - ", style: pageNum), - Text("2", style: pageNumCurrent), + Text("1", style: TextStyles.textStyle20.apply(color: Colors.grey)), + Text(" - ", style: TextStyles.textStyle20.apply(color: Colors.grey)), + Text("2", style: TextStyles.textStyle20.apply(color: Colors.blue)), ], ) ] diff --git a/lib/util/TextStyles.dart b/lib/util/TextStyles.dart new file mode 100644 index 0000000..30e8f97 --- /dev/null +++ b/lib/util/TextStyles.dart @@ -0,0 +1,51 @@ +import 'package:flutter/cupertino.dart'; + +class TextStyles { + static const TextStyle textStyle15 = TextStyle(fontSize: 15); + + static const TextStyle textStyle20 = TextStyle(fontSize: 20); + static const TextStyle textStyle20u = TextStyle(fontSize: 20, decoration: TextDecoration.underline); +} + +class Text15 extends StatelessWidget { + final String text; + + Text15(this.text, {Key key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Text( + this.text, + style: TextStyles.textStyle15 + ); + } +} + + +class Text20 extends StatelessWidget { + final String text; + + Text20(this.text, {Key key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Text( + this.text, + style: TextStyles.textStyle20 + ); + } +} + +class Text20u extends StatelessWidget { + final String text; + + Text20u(this.text, {Key key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Text( + this.text, + style: TextStyles.textStyle20u + ); + } +} \ No newline at end of file