WIP high education graduation calculator

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

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"),
)
],
);
}
}