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/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<PracticePage> {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
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(

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/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<PracticeSetupPage> {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
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<PracticeSetupPage> {
]
),
CheckboxListTile(
title: Text(
"Show correct Answer",
style: TextStyle(fontSize: 20)
),
title: Text20("Show correct Answer"),
value: _showCorrect,
onChanged: (value) {
setState(() {

View file

@ -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<AllInstructionPage> {
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<AllInstructionPage> {
child:Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
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<AllInstructionPage> {
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
)
)
]

View file

@ -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<LeapInstructionPage> {
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<LeapInstructionPage> {
child:Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
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: <Widget>[
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<LeapInstructionPage> {
),
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: <Widget>[
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<LeapInstructionPage> {
visible: divBy400,
child: Column(
children: <Widget>[
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: <Widget>[
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: <Widget>[
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)),
],
)
],

View file

@ -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<ModInstructionPage> {
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<ModInstructionPage> {
child:Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
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<ModInstructionPage> {
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
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: <Widget>[
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)),
],
),
]

View file

@ -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<YearInstructionPage> {
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<YearInstructionPage> {
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
"Take only the last two digits: ",
style: TextStyle(fontSize: 25)
),
Text20("Take only the last two digits: "),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
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: <Widget>[
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: <Widget>[
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<YearInstructionPage> {
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
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: <Widget>[
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: <Widget>[
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: <Widget>[
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: <Widget>[
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: <Widget>[
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: <Widget>[
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)),
],
)
]

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