fully finished total grade calculator

This commit is contained in:
Kima 2023-11-21 21:47:09 +01:00
parent aba39505d9
commit 3410e410d2
2 changed files with 98 additions and 53 deletions

View File

@ -10,14 +10,20 @@ import 'package:flutter_feather_icons/flutter_feather_icons.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class GradeTile extends StatelessWidget { class GradeTile extends StatelessWidget {
const GradeTile(this.grade, const GradeTile(
{Key? key, this.onTap, this.padding, this.censored = false}) this.grade, {
: super(key: key); Key? key,
this.onTap,
this.padding,
this.censored = false,
this.viewOverride = false,
}) : super(key: key);
final Grade grade; final Grade grade;
final void Function()? onTap; final void Function()? onTap;
final EdgeInsetsGeometry? padding; final EdgeInsetsGeometry? padding;
final bool censored; final bool censored;
final bool viewOverride;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -26,7 +32,8 @@ class GradeTile extends StatelessWidget {
bool isTitleItalic = false; bool isTitleItalic = false;
bool isSubtitleItalic = false; bool isSubtitleItalic = false;
EdgeInsets leadingPadding = EdgeInsets.zero; EdgeInsets leadingPadding = EdgeInsets.zero;
bool isSubjectView = SubjectGradesContainer.of(context) != null; bool isSubjectView =
SubjectGradesContainer.of(context) != null || viewOverride;
String subjectName = String subjectName =
grade.subject.renamedTo ?? grade.subject.name.capital(); grade.subject.renamedTo ?? grade.subject.name.capital();
String modeDescription = grade.mode.description.capital(); String modeDescription = grade.mode.description.capital();

View File

@ -2,6 +2,7 @@ import 'dart:math';
import 'package:auto_size_text/auto_size_text.dart'; import 'package:auto_size_text/auto_size_text.dart';
import 'package:filcnaplo/api/providers/update_provider.dart'; import 'package:filcnaplo/api/providers/update_provider.dart';
import 'package:filcnaplo/ui/widgets/grade/grade_tile.dart';
// import 'package:filcnaplo_kreta_api/client/api.dart'; // import 'package:filcnaplo_kreta_api/client/api.dart';
// import 'package:filcnaplo_kreta_api/client/client.dart'; // import 'package:filcnaplo_kreta_api/client/client.dart';
import 'package:filcnaplo_kreta_api/providers/grade_provider.dart'; import 'package:filcnaplo_kreta_api/providers/grade_provider.dart';
@ -88,50 +89,86 @@ class _GradesPageState extends State<GradesPage> {
Map<GradeSubject, double> subjectAvgs = {}; Map<GradeSubject, double> subjectAvgs = {};
tiles.addAll(subjects.map((subject) { if (!gradeCalcMode) {
List<Grade> subjectGrades = getSubjectGrades(subject); tiles.addAll(subjects.map((subject) {
List<Grade> subjectGrades = getSubjectGrades(subject);
double avg = AverageHelper.averageEvals(subjectGrades); double avg = AverageHelper.averageEvals(subjectGrades);
double averageBefore = 0.0; double averageBefore = 0.0;
if (avgDropValue != 0) { if (avgDropValue != 0) {
List<Grade> gradesBefore = List<Grade> gradesBefore =
getSubjectGrades(subject, days: avgDropValue); getSubjectGrades(subject, days: avgDropValue);
averageBefore = averageBefore = avgDropValue == 0
avgDropValue == 0 ? 0.0 : AverageHelper.averageEvals(gradesBefore); ? 0.0
: AverageHelper.averageEvals(gradesBefore);
}
var nullavg = GroupAverage(average: 0.0, subject: subject, uid: "0");
double groupAverage = gradeProvider.groupAverages
.firstWhere((e) => e.subject == subject, orElse: () => nullavg)
.average;
if (avg != 0) subjectAvgs[subject] = avg;
return GradeSubjectTile(
subject,
averageBefore: averageBefore,
average: avg,
groupAverage: avgDropValue == 0 ? groupAverage : 0.0,
onTap: () {
GradeSubjectView(subject, groupAverage: groupAverage)
.push(context, root: true);
},
);
}));
} else {
tiles.clear();
List<Grade> ghostGrades = calculatorProvider.ghosts;
ghostGrades.sort((a, b) => -a.date.compareTo(b.date));
List<GradeTile> _gradeTiles = [];
for (Grade grade in ghostGrades) {
_gradeTiles.add(GradeTile(
grade,
viewOverride: true,
));
} }
var nullavg = GroupAverage(average: 0.0, subject: subject, uid: "0");
double groupAverage = gradeProvider.groupAverages
.firstWhere((e) => e.subject == subject, orElse: () => nullavg)
.average;
if (avg != 0) subjectAvgs[subject] = avg; tiles.add(
_gradeTiles.isNotEmpty
return GradeSubjectTile( ? Panel(
subject, key: ValueKey(gradeCalcMode),
averageBefore: averageBefore, title: Text(
average: avg, "Ghost Grades".i18n,
groupAverage: avgDropValue == 0 ? groupAverage : 0.0, ),
onTap: () { child: Column(
GradeSubjectView(subject, groupAverage: groupAverage) children: _gradeTiles,
.push(context, root: true); ),
}, )
: const SizedBox(),
); );
})); }
if (tiles.isNotEmpty) { if (tiles.isNotEmpty || gradeCalcMode) {
tiles.insert(0, yearlyGraph); tiles.insert(0, yearlyGraph);
tiles.insert(1, gradesCount); tiles.insert(1, gradesCount);
tiles.insert(2, FailWarning(subjectAvgs: subjectAvgs)); if (!gradeCalcMode) {
tiles.insert( tiles.insert(2, FailWarning(subjectAvgs: subjectAvgs));
tiles.insert(
3, 3,
PanelTitle( PanelTitle(
title: Text(avgDropValue == 0 title: Text(
? "Subjects".i18n avgDropValue == 0 ? "Subjects".i18n : "Subjects_changes".i18n,
: "Subjects_changes".i18n))); )),
tiles.insert(4, const PanelHeader(padding: EdgeInsets.only(top: 12.0))); );
tiles.add(const PanelFooter(padding: EdgeInsets.only(bottom: 12.0)));
tiles.add(const Padding(padding: EdgeInsets.only(bottom: 24.0))); tiles.insert(4, const PanelHeader(padding: EdgeInsets.only(top: 12.0)));
tiles.add(const PanelFooter(padding: EdgeInsets.only(bottom: 12.0)));
}
tiles.add(Padding(
padding: EdgeInsets.only(bottom: !gradeCalcMode ? 24.0 : 250.0),
));
} else { } else {
tiles.insert( tiles.insert(
0, 0,
@ -165,7 +202,7 @@ class _GradesPageState extends State<GradesPage> {
gradeProvider.groupAverages.length gradeProvider.groupAverages.length
: 0.0; : 0.0;
if (subjectAvg > 0) { if (subjectAvg > 0 && !gradeCalcMode) {
tiles.add(Row( tiles.add(Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@ -243,7 +280,7 @@ class _GradesPageState extends State<GradesPage> {
? gradeProvider.grades ? gradeProvider.grades
.where((e) => e.type == GradeType.midYear) .where((e) => e.type == GradeType.midYear)
.toList() .toList()
: calculatorProvider.grades.toList()); : calculatorProvider.grades);
final prevStudentAvg = AverageHelper.averageEvals(gradeProvider.grades final prevStudentAvg = AverageHelper.averageEvals(gradeProvider.grades
.where((e) => e.type == GradeType.midYear) .where((e) => e.type == GradeType.midYear)
@ -323,21 +360,22 @@ class _GradesPageState extends State<GradesPage> {
snap: false, snap: false,
surfaceTintColor: Theme.of(context).scaffoldBackgroundColor, surfaceTintColor: Theme.of(context).scaffoldBackgroundColor,
actions: [ actions: [
Padding( if (!gradeCalcMode)
padding: const EdgeInsets.symmetric( Padding(
horizontal: 5.0, vertical: 0.0), padding: const EdgeInsets.symmetric(
child: IconButton( horizontal: 5.0, vertical: 0.0),
splashRadius: 24.0, child: IconButton(
onPressed: () { splashRadius: 24.0,
// SoonAlert.show(context: context); onPressed: () {
gradeCalcTotal(context); // SoonAlert.show(context: context);
}, gradeCalcTotal(context);
icon: Icon( },
FeatherIcons.plus, icon: Icon(
color: AppColors.of(context).text, FeatherIcons.plus,
color: AppColors.of(context).text,
),
), ),
), ),
),
// profile Icon // profile Icon
Padding( Padding(