input check on distance traveled and track conditions

This commit is contained in:
Nico
2025-06-02 20:15:42 +02:00
parent af2637c1b8
commit 2574752ebb
7 changed files with 62 additions and 29 deletions

View File

@@ -1,3 +1,4 @@
import 'package:fforte/screens/helper/snack_bar_helper.dart';
import 'package:flutter/material.dart';
import 'package:fforte/l10n/app_localizations.dart';
@@ -51,9 +52,9 @@ class StreckeUSpurbedingungenState extends State<StreckeUSpurbedingungen> {
}
// Track Conditions
// widget.spGutController.addListener(onTrackConditionsUpdated);
// widget.spMittelController.addListener(onTrackConditionsUpdated);
// widget.spSchlechtController.addListener(onTrackConditionsUpdated);
widget.spGutController.addListener(onTrackConditionsUpdated);
widget.spMittelController.addListener(onTrackConditionsUpdated);
widget.spSchlechtController.addListener(onTrackConditionsUpdated);
// if one of the values is "" the excursion is edited for the first time. On which value i check here is unnecessarry
if (widget.spGutController.text == "") {
@@ -86,27 +87,29 @@ class StreckeUSpurbedingungenState extends State<StreckeUSpurbedingungen> {
// }
// }
// void onTrackConditionsUpdated() {
// try {
// double kmGood = double.parse(widget.spGutController.text);
// double kmMiddle = double.parse(widget.spMittelController.text);
// double kmBad = double.parse(widget.spSchlechtController.text);
// // double gesKm = (kmGood + kmMiddle + kmBad);
//
// // if (gesKm == 0) {
// // goodPercent = "0";
// // middlePercent = "0";
// // badPercent = "0";
// // } else {
// // goodPercent = (kmGood / gesKm * 100).round().toString();
// // middlePercent = (kmMiddle / gesKm * 100).round().toString();
// // badPercent = (kmBad / gesKm * 100).round().toString();
// // }
// setState(() {});
// } catch (e) {
// return;
// }
// }
void onTrackConditionsUpdated() {
try {
double kmGood = double.parse(widget.spGutController.text);
double kmMiddle = double.parse(widget.spMittelController.text);
double kmBad = double.parse(widget.spSchlechtController.text);
double kmAuto = double.parse(widget.kmAutoController.text);
double kmFuss = double.parse(widget.kmFussController.text);
double kmRad = double.parse(widget.kmRadController.text);
double gesConditionsKm = (kmGood + kmMiddle + kmBad);
double gesDistanceKm = (kmAuto + kmFuss + kmRad);
if (gesConditionsKm > gesDistanceKm) {
SnackBarHelper.showSnackBarMessage(context, AppLocalizations.of(context)!.bedingungenGroesserAlsStrecke);
}
setState(() {});
} catch (e) {
return;
}
}
@override
Widget build(BuildContext context) {