Switched to custom "Text" classes for different text, cleaner but not sure if 'the way'

This commit is contained in:
BroodjeAap 2020-12-30 16:30:11 +01:00
parent 70eb31c7c9
commit 077e2d15c6
7 changed files with 145 additions and 196 deletions

View file

@ -10,6 +10,7 @@ import 'package:ohthatsa/pages/practice/thing/PracticeThingMonth.dart';
import 'package:ohthatsa/other/AppDrawer.dart'; import 'package:ohthatsa/other/AppDrawer.dart';
import 'package:ohthatsa/pages/practice/PracticeType.dart'; import 'package:ohthatsa/pages/practice/PracticeType.dart';
import 'package:ohthatsa/pages/practice/thing/PracticeThingYear.dart'; import 'package:ohthatsa/pages/practice/thing/PracticeThingYear.dart';
import 'package:ohthatsa/util/TextStyles.dart';
class PracticePage extends StatefulWidget { class PracticePage extends StatefulWidget {
@ -137,24 +138,9 @@ class PracticePageState extends State<PracticePage> {
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[ children: <Widget>[
Text( Text20("Correct: " + _correct.toString()),
"Correct: " + _correct.toString(), Text20((_startCount - _count).toString() + " Left"),
style: TextStyle( Text20("Incorrect: " + _incorrect.toString()),
fontSize: 20,
)
),
Text(
(_startCount - _count).toString() + " Left",
style: TextStyle(
fontSize: 20,
)
),
Text(
"Incorrect: " + _incorrect.toString(),
style: TextStyle(
fontSize: 20,
)
)
], ],
), ),
Column( Column(

View file

@ -5,6 +5,7 @@ import 'package:ohthatsa/pages/practice/PracticeDatabase.dart';
import 'package:ohthatsa/pages/practice/PracticeSetup.dart'; import 'package:ohthatsa/pages/practice/PracticeSetup.dart';
import 'package:ohthatsa/pages/practice/PracticeType.dart'; import 'package:ohthatsa/pages/practice/PracticeType.dart';
import 'package:ohthatsa/util/Extensions.dart'; import 'package:ohthatsa/util/Extensions.dart';
import 'package:ohthatsa/util/TextStyles.dart';
import 'instructions/MonthInstructionPage.dart'; import 'instructions/MonthInstructionPage.dart';
@ -89,10 +90,7 @@ class _PracticeSetupState extends State<PracticeSetupPage> {
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[ children: <Widget>[
Text( Text20("How many rounds"),
"How many rounds",
style: TextStyle(fontSize: 20),
),
NumberPicker.horizontal( NumberPicker.horizontal(
initialValue: _count, initialValue: _count,
minValue: 1, minValue: 1,
@ -103,10 +101,7 @@ class _PracticeSetupState extends State<PracticeSetupPage> {
] ]
), ),
CheckboxListTile( CheckboxListTile(
title: Text( title: Text20("Show correct Answer"),
"Show correct Answer",
style: TextStyle(fontSize: 20)
),
value: _showCorrect, value: _showCorrect,
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {

View file

@ -3,6 +3,7 @@ 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/DayCalculator.dart';
import 'package:ohthatsa/util/Months.dart'; import 'package:ohthatsa/util/Months.dart';
import 'package:ohthatsa/util/TextStyles.dart';
class AllInstructionPage extends StatefulWidget { class AllInstructionPage extends StatefulWidget {
@override @override
@ -16,17 +17,6 @@ class _AllInstructionPageState extends State<AllInstructionPage> {
super.initState(); 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 = [ static const daysOfTheWeek = [
"Sunday", "Sunday",
"Monday", "Monday",
@ -52,22 +42,22 @@ class _AllInstructionPageState extends State<AllInstructionPage> {
child:Column( child:Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text("To calculate the weekday", style: textStyle), Text20("To calculate the weekday"),
Text("Add all the values together:", style: textStyle), Text20("Add all the values together:"),
Text("Day of the Month", style: textStyle), Text20("Day of the Month"),
Text("+", style: TextStyle(fontSize: 15)), Text15("+"),
Text("Month Value", style: textStyle), Text20("Month Value"),
Text("+", style: TextStyle(fontSize: 15)), Text15("+"),
Text("Year Value", style: textStyle), Text20("Year Value"),
Text("+", style: TextStyle(fontSize: 15)), Text15("+"),
Text("Century Value", style: textStyle), Text20("Century Value"),
Text("-", style: TextStyle(fontSize: 15)), Text15("-"),
Text("Leap Value (1 or 0)", style: textStyle), Text20("Leap Value (1 or 0)"),
Text("(if in January/February)", style: TextStyle(fontSize: 15)), Text15("(if in January/February)"),
Text("", style: TextStyle(fontSize: 15)), Text15(""),
Text("Mod the result by 7", style: textStyle), Text20("Mod the result by 7"),
Text("", style: TextStyle(fontSize: 15)), Text15(""),
Text("And check what day it is:", style: textStyle), Text20("And check what day it is:"),
Table( Table(
children: List.generate(daysOfTheWeek.length, (i) => children: List.generate(daysOfTheWeek.length, (i) =>
TableRow( TableRow(
@ -76,14 +66,14 @@ class _AllInstructionPageState extends State<AllInstructionPage> {
child: Text( child: Text(
daysOfTheWeek[i], daysOfTheWeek[i],
textAlign: TextAlign.right, textAlign: TextAlign.right,
style: TextStyle(fontSize: 20) style: TextStyles.textStyle20
) )
), ),
TableCell( TableCell(
child: Text( child: Text(
i.toString(), i.toString(),
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle(fontSize: 20) style: TextStyles.textStyle20
) )
) )
] ]

View file

@ -2,7 +2,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/DayCalculator.dart';
import 'package:ohthatsa/util/Months.dart'; import 'package:ohthatsa/util/TextStyles.dart';
class LeapInstructionPage extends StatefulWidget { class LeapInstructionPage extends StatefulWidget {
@override @override
@ -31,17 +31,6 @@ class _LeapInstructionPageState extends State<LeapInstructionPage> {
setState(() {}); 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 @override
Widget build(BuildContext context){ Widget build(BuildContext context){
return Scaffold( return Scaffold(
@ -57,17 +46,17 @@ class _LeapInstructionPageState extends State<LeapInstructionPage> {
child:Column( child:Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text("A year is a leap year if...", style: textStyle), Text20("A year is a leap year if..."),
Text("It is divisible by 4, unless...", style: textStyle), Text20("It is divisible by 4, unless..."),
Text("It's also divisible by 100, unless...", style: textStyle), Text20("It's also divisible by 100, unless..."),
Text("It's divisible by 400", style: textStyle), Text20("It's divisible by 400"),
Spacer(), Spacer(),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text("1", style: pageNumCurrent), Text("1", style: TextStyles.textStyle20.apply(color: Colors.blue)),
Text(" - ", style: pageNum), Text(" - ", style: TextStyles.textStyle20.apply(color: Colors.grey)),
Text("2", style: pageNum), Text("2", style: TextStyles.textStyle20.apply(color: Colors.grey)),
], ],
) )
] ]
@ -86,14 +75,14 @@ class _LeapInstructionPageState extends State<LeapInstructionPage> {
), ),
Visibility( Visibility(
visible: divBy4, visible: divBy4,
child: Text(year.toString() + " is divisible by 4", style: textStyle) child: Text20(year.toString() + " is divisible by 4")
), ),
Visibility( Visibility(
visible: divBy100, visible: divBy100,
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Text("But...", style: textStyle), Text20("But..."),
Text(year.toString() + " is also divisible by 100", style: textStyle) Text20(year.toString() + " is also divisible by 100")
], ],
) )
), ),
@ -101,26 +90,26 @@ class _LeapInstructionPageState extends State<LeapInstructionPage> {
visible: divBy400, visible: divBy400,
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Text("But...", style: textStyle), Text20("But..."),
Text(year.toString() + " is also divisible by 400", style: textStyle) Text20(year.toString() + " is also divisible by 400")
], ],
) )
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text("So " + year.toString() + " is", style: textStyle), Text20("So " + year.toString() + " is"),
Text(this.isLeapYear ? " " : " not ", style: textStyle), Text20(this.isLeapYear ? " " : " not "),
Text("a leap year", style: textStyle) Text20("a leap year")
], ],
), ),
Spacer(), Spacer(),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text("1", style: pageNum), Text("1", style: TextStyles.textStyle20.apply(color: Colors.grey)),
Text(" - ", style: pageNum), Text(" - ", style: TextStyles.textStyle20.apply(color: Colors.grey)),
Text("2", style: pageNumCurrent), Text("2", style: TextStyles.textStyle20.apply(color: Colors.blue)),
], ],
) )
], ],

View file

@ -3,6 +3,7 @@ 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/DayCalculator.dart';
import 'package:ohthatsa/util/Months.dart'; import 'package:ohthatsa/util/Months.dart';
import 'package:ohthatsa/util/TextStyles.dart';
class ModInstructionPage extends StatefulWidget { class ModInstructionPage extends StatefulWidget {
@override @override
@ -27,17 +28,6 @@ class _ModInstructionPageState extends State<ModInstructionPage> {
setState(() {}); 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 @override
Widget build(BuildContext context){ Widget build(BuildContext context){
return Scaffold( return Scaffold(
@ -53,7 +43,7 @@ class _ModInstructionPageState extends State<ModInstructionPage> {
child:Column( child:Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text("Modulus (Mod) is the remainder after dividing", style: textStyle), Text20("Modulus (Mod) is the remainder after dividing"),
NumberPicker.integer( NumberPicker.integer(
initialValue: value, initialValue: value,
minValue: 0, minValue: 0,
@ -63,18 +53,18 @@ class _ModInstructionPageState extends State<ModInstructionPage> {
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text(value.toString(), style: valueStyle), Text(value.toString(), style: TextStyles.textStyle20.apply(color: Colors.green)),
Text(" divided by 7 is " + div.toString(), style: textStyle), 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( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text("So the result of ", style: textStyle), Text20("So the result of "),
Text(value.toString(), style: valueStyle), Text(value.toString(), style: TextStyles.textStyle20.apply(color: Colors.green)),
Text(" mod 7 is ", style: textStyle), Text20(" mod 7 is "),
Text(remainder.toString(), style: textStyleU), Text(remainder.toString(), style: TextStyles.textStyle20.apply(decoration: TextDecoration.underline)),
], ],
), ),
] ]

View file

@ -4,6 +4,7 @@ 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/DayCalculator.dart';
import 'package:ohthatsa/util/TextStyles.dart';
import 'package:term_glyph/term_glyph.dart' as glyph; import 'package:term_glyph/term_glyph.dart' as glyph;
class YearInstructionPage extends StatefulWidget { class YearInstructionPage extends StatefulWidget {
@ -36,30 +37,7 @@ class _YearInstructionPageState extends State<YearInstructionPage> {
setState(() {}); 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -75,62 +53,32 @@ class _YearInstructionPageState extends State<YearInstructionPage> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text( Text20("Take only the last two digits: "),
"Take only the last two digits: ",
style: TextStyle(fontSize: 25)
),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text( Text("YY", style: TextStyles.textStyle20.apply(color: Colors.grey)),
"YY", Text("YY", style: TextStyles.textStyle20.apply(color: Colors.green)),
style: TextStyle(
color: Colors.grey,
fontSize: 25
)
),
Text(
"YY",
style: YYStyle
)
], ],
), ),
Text( Text20("Calculate:"),
"Calculate:",
style: TextStyle(fontSize: 25)
),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text( Text20("("),
"(", Text("YY", style: TextStyles.textStyle20.apply(color: Colors.green)),
style: formulaStyle, Text20(" + floor("),
), Text("YY", style: TextStyles.textStyle20.apply(color: Colors.green)),
Text( Text20(" / 4)) % 7"),
"YY",
style: YYStyle
),
Text(
" + floor(",
style: formulaStyle
),
Text(
"YY",
style: YYStyle
),
Text(
" / 4)) % 7",
style: formulaStyle
),
], ],
), ),
Spacer(), Spacer(),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text("1", style: pageNumCurrent), Text("1", style: TextStyles.textStyle20.apply(color: Colors.blue)),
Text(" - ", style: pageNum), Text(" - ", style: TextStyles.textStyle20.apply(color: Colors.grey)),
Text("2", style: pageNum), Text("2", style: TextStyles.textStyle20.apply(color: Colors.grey)),
], ],
) )
], ],
@ -151,67 +99,67 @@ class _YearInstructionPageState extends State<YearInstructionPage> {
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text("For ", style: formulaStyle), Text20("For "),
Text(centuriesString, style: formulaStyle), Text20(centuriesString),
Text(year.toString().substring(2), style: YYStyle), Text(year.toString().substring(2), style: TextStyles.textStyle20.apply(color: Colors.green)),
Text(" our formula becomes: ", style: formulaStyle), Text20(" our formula becomes: "),
], ],
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text("(", style: formulaStyle), Text20("("),
Text(yyString, style: YYStyle), Text(yyString, style: TextStyles.textStyle20.apply(color: Colors.green)),
Text(" + floor(", style: formulaStyle), Text20(" + floor("),
Text(yyString, style: YYStyleU), Text(yyString, style: TextStyles.textStyle20u.apply(color: Colors.green)),
Text(" / 4", style: formulaStyleU), Text20u(" / 4"),
Text(")) % 7", style: formulaStyle), Text20(")) % 7"),
], ],
), ),
Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)), Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text("(", style: formulaStyle), Text20("("),
Text(yyString, style: YYStyle), Text(yyString, style: TextStyles.textStyle20u.apply(color: Colors.green)),
Text(" + ", style: formulaStyle), Text20(" + "),
Text("floor(" + yyDiv4.toString() + ")", style: formulaStyleU), Text20u("floor(" + yyDiv4.toString() + ")"),
Text(") % 7", style: formulaStyle), Text20(") % 7"),
], ],
), ),
Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)), Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text("(", style: formulaStyleU), Text20u("("),
Text(yyString, style: YYStyleU), Text(yyString, style: TextStyles.textStyle20u.apply(color: Colors.green)),
Text(" + " + yyDiv4Floored.toString() + ")", style: formulaStyleU), Text20u(" + " + yyDiv4Floored.toString() + ")"),
Text(" % 7", style: formulaStyle), Text20u(" % 7"),
], ],
), ),
Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)), Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text((yy + yyDiv4Floored).toString(), style: formulaStyleU), Text20u((yy + yyDiv4Floored).toString()),
Text(" % 7", style: formulaStyleU), Text20u(" % 7"),
], ],
), ),
Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)), Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text("So the year value of " + year.toString() + " is: ", style: formulaStyle), Text20("So the year value of " + year.toString() + " is: "),
Text(yearValue.toString(), style: formulaStyleU), Text20u(yearValue.toString()),
], ],
), ),
Spacer(), Spacer(),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text("1", style: pageNum), Text("1", style: TextStyles.textStyle20.apply(color: Colors.grey)),
Text(" - ", style: pageNum), Text(" - ", style: TextStyles.textStyle20.apply(color: Colors.grey)),
Text("2", style: pageNumCurrent), Text("2", style: TextStyles.textStyle20.apply(color: Colors.blue)),
], ],
) )
] ]

51
lib/util/TextStyles.dart Normal file
View file

@ -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
);
}
}