refactored more stats table stuff, much cleaner now
This commit is contained in:
parent
14caf52020
commit
7cf335cdff
1 changed files with 39 additions and 96 deletions
|
@ -4,6 +4,7 @@ import 'package:ohthatsa/AppDrawer.dart';
|
||||||
import 'package:ohthatsa/pages/practice/PracticeDatabase.dart';
|
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';
|
||||||
|
|
||||||
class PracticeSetupPage extends StatefulWidget {
|
class PracticeSetupPage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
|
@ -23,19 +24,45 @@ class _PracticeSetupState extends State<PracticeSetupPage> {
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
Text getStatTableText(double value){
|
TableRow getStatTableRow(AsyncSnapshot<Map<String, double>> snapshot, PracticeType practiceType){
|
||||||
|
final typeString = practiceType.toString().split(".").last;
|
||||||
|
return TableRow(
|
||||||
|
children: <Widget>[
|
||||||
|
FlatButton(
|
||||||
|
child: Text(typeString.capitalize()),
|
||||||
|
color: Colors.blue,
|
||||||
|
textColor: Colors.white,
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pushNamed(
|
||||||
|
context,
|
||||||
|
'/practice/practice',
|
||||||
|
arguments: PracticeSetup(_count, _showCorrect, practiceType)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
getStatTableText(snapshot.hasData ? snapshot.data["7d $typeString"] : null),
|
||||||
|
getStatTableText(snapshot.hasData ? snapshot.data["30d $typeString"] : null),
|
||||||
|
getStatTableText(snapshot.hasData ? snapshot.data["All $typeString"] : null),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget getStatTableText(double value){
|
||||||
var text = "-";
|
var text = "-";
|
||||||
var color = Colors.grey.shade500;
|
var color = Colors.grey.shade500;
|
||||||
if (value != null){
|
if (value != null){
|
||||||
text = value.toString() + "%";
|
text = value.toString() + "%";
|
||||||
color = value >= 70 ? Colors.green : Colors.red;
|
color = value >= 70 ? Colors.green : Colors.red;
|
||||||
}
|
}
|
||||||
return Text(
|
return Align(
|
||||||
text,
|
alignment: Alignment.center,
|
||||||
textAlign: TextAlign.center,
|
child: Text(
|
||||||
style: TextStyle(
|
text,
|
||||||
fontSize: 25,
|
style: TextStyle(
|
||||||
color: color
|
fontSize: 25,
|
||||||
|
color: color,
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -94,95 +121,11 @@ class _PracticeSetupState extends State<PracticeSetupPage> {
|
||||||
Text("All", textAlign: TextAlign.center, style: TextStyle(fontSize: 25))
|
Text("All", textAlign: TextAlign.center, style: TextStyle(fontSize: 25))
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
TableRow(
|
getStatTableRow(snapshot, PracticeType.month),
|
||||||
children: <Widget>[
|
getStatTableRow(snapshot, PracticeType.century),
|
||||||
FlatButton(
|
getStatTableRow(snapshot, PracticeType.leap),
|
||||||
child: Text("Month"),
|
getStatTableRow(snapshot, PracticeType.mod),
|
||||||
color: Colors.blue,
|
getStatTableRow(snapshot, PracticeType.all),
|
||||||
textColor: Colors.white,
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pushNamed(
|
|
||||||
context,
|
|
||||||
'/practice/practice',
|
|
||||||
arguments: PracticeSetup(_count, _showCorrect, PracticeType.month)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
getStatTableText(snapshot.data["7d month"]),
|
|
||||||
getStatTableText(snapshot.data["30d month"]),
|
|
||||||
getStatTableText(snapshot.data["All month"]),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
TableRow(
|
|
||||||
children: <Widget>[
|
|
||||||
FlatButton(
|
|
||||||
child: Text("Century"),
|
|
||||||
color: Colors.blue,
|
|
||||||
textColor: Colors.white,
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pushNamed(
|
|
||||||
context,
|
|
||||||
'/practice/practice',
|
|
||||||
arguments: PracticeSetup(_count, _showCorrect, PracticeType.century)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
getStatTableText(snapshot.data["7d century"]),
|
|
||||||
getStatTableText(snapshot.data["30d century"]),
|
|
||||||
getStatTableText(snapshot.data["All century"]),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
TableRow(
|
|
||||||
children: <Widget>[
|
|
||||||
FlatButton(
|
|
||||||
child: Text("Leap"),
|
|
||||||
color: Colors.blue,
|
|
||||||
textColor: Colors.white,
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pushNamed(
|
|
||||||
context,
|
|
||||||
'/practice/practice',
|
|
||||||
arguments: PracticeSetup(_count, _showCorrect, PracticeType.leap)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
getStatTableText(snapshot.data["7d leap"]),
|
|
||||||
getStatTableText(snapshot.data["30d leap"]),
|
|
||||||
getStatTableText(snapshot.data["All leap"]),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
TableRow(
|
|
||||||
children: <Widget>[
|
|
||||||
FlatButton(
|
|
||||||
child: Text("Mod7"),
|
|
||||||
color: Colors.blue,
|
|
||||||
textColor: Colors.white,
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pushNamed(
|
|
||||||
context,
|
|
||||||
'/practice/practice',
|
|
||||||
arguments: PracticeSetup(_count, _showCorrect, PracticeType.mod)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
getStatTableText(snapshot.data["7d mod"]),
|
|
||||||
getStatTableText(snapshot.data["30d mod"]),
|
|
||||||
getStatTableText(snapshot.data["All mod"]),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
TableRow(
|
|
||||||
children: <Widget>[
|
|
||||||
FlatButton(
|
|
||||||
child: Text("All"),
|
|
||||||
color: Colors.blue,
|
|
||||||
textColor: Colors.white,
|
|
||||||
onPressed: () {},
|
|
||||||
),
|
|
||||||
getStatTableText(snapshot.data["7d all"]),
|
|
||||||
getStatTableText(snapshot.data["30d all"]),
|
|
||||||
getStatTableText(snapshot.data["All all"]),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue