WIP high education graduation calculator

This commit is contained in:
Elias Müller 2024-03-23 15:42:31 +01:00
parent e7192008c0
commit c4f5be2205
5 changed files with 179 additions and 5 deletions

View File

@ -1,9 +1,9 @@
import 'dart:convert';
import 'dart:developer';
import 'package:localstore/localstore.dart';
import 'apiResponse.dart';
import 'webuntis/webuntisError.dart';
abstract class RequestCache<T extends ApiResponse?> {
static const int cacheNothing = 0;
@ -30,16 +30,18 @@ abstract class RequestCache<T extends ApiResponse?> {
if(renew == null || !renew!) return;
}
T? newValue;
try {
T newValue = await onLoad();
onUpdate(newValue);
newValue = await onLoad();
onUpdate(newValue as T);
Localstore.instance.collection(file).doc(document).set({
"json": jsonEncode(newValue),
"lastupdate": DateTime.now().millisecondsSinceEpoch
});
} on WebuntisError catch(e) {
onError(e);
} catch(e) {
log("Error while fetching/ parsing. Raw server response: ${newValue?.rawResponse.body ?? "no response"}");
onError(Exception(e.toString()));
}
}

View File

@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
import 'package:marianum_mobile/view/pages/more/highEduGraduationCalculator/models/subject.dart';
import 'package:marianum_mobile/view/pages/more/highEduGraduationCalculator/selectLkView.dart';
class HighEduGraduationCalculator extends StatefulWidget {
const HighEduGraduationCalculator({super.key});
@override
State<HighEduGraduationCalculator> createState() => _HighEduGraduationCalculatorState();
}
class _HighEduGraduationCalculatorState extends State<HighEduGraduationCalculator> {
SubjectCollection allSubjects = SubjectCollection([
Subject(displayName: "Mathe", lkApplicable: true),
Subject(displayName: "Physik", lkApplicable: true),
Subject(displayName: "Chemie", lkApplicable: true),
Subject(displayName: "Biologie", lkApplicable: true),
Subject(displayName: "Englisch", lkApplicable: true),
Subject(displayName: "Latein", lkApplicable: true),
]);
SubjectCollection? lkSubjects;
int currentStep = 0;
List<Step> steps() => [
Step(title: const Text("Willkommen"), content: Text("test")),
Step(title: const Text("Leistungskurse wählen"), content: lkSubjectsStep()),
const Step(title: Text("Grundkurse wählen"), content: Text("Test")),
const Step(title: Text("Prüfungsfächer wählen"), content: Text("Test")),
const Step(title: Text("Ergebnis auswerten"), content: Text("Test")),
];
Widget lkSubjectsStep() {
return Column(
children: [
Text(lkSubjects?.subjects.where((e) => e.isLk()).map((e) => e.displayName).join(", ") ?? "Keine Auswahl"),
TextButton(
onPressed: () {
showDialog(context: context, builder: (context) => SelectLkView(all: allSubjects, update: () => setState(() => { })));
},
child: const Text("Ändern"),
),
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Abitur Notenrechner"),
),
body: Stepper(
type: StepperType.vertical,
steps: steps(),
currentStep: currentStep,
onStepContinue: () {
setState(() {
currentStep++;
});
},
controlsBuilder: (context, details) {
return Row(
children: [
TextButton(
onPressed: () => details.onStepContinue,
child: const Text("Weiter"),
)
],
);
},
)
);
}
}

View File

@ -0,0 +1,48 @@
import 'package:flutter/material.dart';
import 'package:marianum_mobile/widget/centeredLeading.dart';
enum SubjectState {
none,
isLk,
isGk,
}
class HighEduGraduationConstants {
static const int maxLks = 2;
static const int maxGks = 9;
}
class SubjectCollection {
List<Subject> subjects;
SubjectCollection(this.subjects);
}
class Subject {
String displayName;
bool lkApplicable;
SubjectState _subjectState = SubjectState.none;
bool isLk() => _subjectState == SubjectState.isLk;
bool isGk() => _subjectState == SubjectState.isGk;
bool canLk(List<Subject> other) => lkApplicable && other.where((s) => s.isLk()).length < HighEduGraduationConstants.maxLks;
bool canGk(List<Subject> other) => !isLk() && other.where((s) => s.isGk()).length < HighEduGraduationConstants.maxGks;
set unsafeSubjectSet(SubjectState newState) => _subjectState = newState;
set unsafeLkToggle(bool isLk) {
_subjectState = isLk ? SubjectState.isLk : SubjectState.none;
}
ListTile get asTile => ListTile(
leading: const CenteredLeading(Icon(Icons.subject_outlined)),
title: Text(displayName),
trailing: Checkbox(
value: isGk(),
onChanged: (e) => {},
),
);
Subject({required this.displayName, required this.lkApplicable});
}

View File

@ -0,0 +1,47 @@
import 'package:flutter/material.dart';
import 'package:marianum_mobile/view/pages/more/highEduGraduationCalculator/models/subject.dart';
import 'package:marianum_mobile/widget/centeredLeading.dart';
class SelectLkView extends StatefulWidget {
final SubjectCollection all;
final void Function() update;
const SelectLkView({required this.all, required this.update, super.key});
@override
State<SelectLkView> createState() => _SelectLkViewState();
}
class _SelectLkViewState extends State<SelectLkView> {
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text("Leistungskurse"),
content: Column(
mainAxisSize: MainAxisSize.min,
children: widget.all.subjects.map((e) {
return ListTile(
leading: const CenteredLeading(Icon(Icons.subject_outlined)),
title: Text(e.displayName),
trailing: Checkbox(
value: e.isLk(),
onChanged: e.isLk() || e.canLk(widget.all.subjects) ? (value) {
setState(() {
e.unsafeLkToggle = value!;
});
} : null,
),
);
}).toList(),
),
actions: [
TextButton(
onPressed: () {
widget.update();
Navigator.of(context).pop();
},
child: const Text("Fertig"),
)
],
);
}
}

View File

@ -4,6 +4,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:in_app_review/in_app_review.dart';
import 'package:marianum_mobile/extensions/renderNotNull.dart';
import 'package:marianum_mobile/view/pages/more/highEduGraduationCalculator/highEduGraduationCalculator.dart';
import 'package:persistent_bottom_nav_bar_v2/persistent-tab-view.dart';
import '../../widget/ListItem.dart';
@ -35,6 +36,7 @@ class Overhang extends StatelessWidget {
const ListItemNavigator(icon: Icons.newspaper, text: "Marianum Message", target: Message()),
const ListItemNavigator(icon: Icons.room, text: "Raumplan", target: Roomplan()),
const ListItemNavigator(icon: Icons.calculate, text: "Notendurschnittsrechner", target: GradeAverage()),
const ListItemNavigator(icon: Icons.backup_table_outlined, text: "Abirechner", target: HighEduGraduationCalculator()),
const ListItemNavigator(icon: Icons.calendar_month, text: "Schulferien", target: Holidays()),
const Divider(),
ListTile(