let AI comment everything because well... yeah...
This commit is contained in:
@@ -1,13 +1,28 @@
|
||||
// * Widget for recording travel distances and track conditions during excursions
|
||||
// * Features:
|
||||
// * - Distance tracking by transportation mode (car, foot, bicycle)
|
||||
// * - Track condition assessment (good, medium, poor)
|
||||
// * - Automatic validation of total distances
|
||||
// * - Input validation with user feedback
|
||||
|
||||
import 'package:fforte/screens/helper/snack_bar_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fforte/l10n/app_localizations.dart';
|
||||
|
||||
/// Widget for managing travel distances and track conditions
|
||||
/// Tracks both how the distance was covered and the quality of tracks found
|
||||
class StreckeUSpurbedingungen extends StatefulWidget {
|
||||
/// Controller for distance traveled by car
|
||||
final TextEditingController kmAutoController;
|
||||
/// Controller for distance traveled on foot
|
||||
final TextEditingController kmFussController;
|
||||
/// Controller for distance traveled by bicycle
|
||||
final TextEditingController kmRadController;
|
||||
/// Controller for distance with good track conditions
|
||||
final TextEditingController spGutController;
|
||||
/// Controller for distance with medium track conditions
|
||||
final TextEditingController spMittelController;
|
||||
/// Controller for distance with poor track conditions
|
||||
final TextEditingController spSchlechtController;
|
||||
|
||||
const StreckeUSpurbedingungen({
|
||||
@@ -24,6 +39,7 @@ class StreckeUSpurbedingungen extends StatefulWidget {
|
||||
StreckeUSpurbedingungenState createState() => StreckeUSpurbedingungenState();
|
||||
}
|
||||
|
||||
/// State class for the distance and track conditions widget
|
||||
class StreckeUSpurbedingungenState extends State<StreckeUSpurbedingungen> {
|
||||
// vars for percent text fields
|
||||
// String carPercent = "0";
|
||||
@@ -44,7 +60,7 @@ class StreckeUSpurbedingungenState extends State<StreckeUSpurbedingungen> {
|
||||
// widget.kmFussController.addListener(onDistanceTravledUpdated);
|
||||
// widget.kmRadController.addListener(onDistanceTravledUpdated);
|
||||
|
||||
// if one of the values is "" the excursion is edited for the first time. On which value i check here is unnecessarry
|
||||
// Initialize distance values if not set
|
||||
if (widget.kmAutoController.text == "") {
|
||||
widget.kmAutoController.text = "0";
|
||||
widget.kmFussController.text = "0";
|
||||
@@ -56,7 +72,7 @@ class StreckeUSpurbedingungenState extends State<StreckeUSpurbedingungen> {
|
||||
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
|
||||
// Initialize track condition values if not set
|
||||
if (widget.spGutController.text == "") {
|
||||
widget.spGutController.text = "0";
|
||||
widget.spMittelController.text = "0";
|
||||
@@ -87,20 +103,25 @@ class StreckeUSpurbedingungenState extends State<StreckeUSpurbedingungen> {
|
||||
// }
|
||||
// }
|
||||
|
||||
/// Validate that track condition distances don't exceed total travel distance
|
||||
/// Shows warning if track conditions total is greater than distance traveled
|
||||
void onTrackConditionsUpdated() {
|
||||
try {
|
||||
// Parse track condition distances
|
||||
double kmGood = double.parse(widget.spGutController.text);
|
||||
double kmMiddle = double.parse(widget.spMittelController.text);
|
||||
double kmBad = double.parse(widget.spSchlechtController.text);
|
||||
|
||||
// Parse travel distances
|
||||
double kmAuto = double.parse(widget.kmAutoController.text);
|
||||
double kmFuss = double.parse(widget.kmFussController.text);
|
||||
double kmRad = double.parse(widget.kmRadController.text);
|
||||
|
||||
// Calculate totals
|
||||
double gesConditionsKm = (kmGood + kmMiddle + kmBad);
|
||||
double gesDistanceKm = (kmAuto + kmFuss + kmRad);
|
||||
|
||||
|
||||
// Show warning if track conditions exceed distance
|
||||
if (gesConditionsKm > gesDistanceKm) {
|
||||
SnackBarHelper.showSnackBarMessage(context, AppLocalizations.of(context)!.bedingungenGroesserAlsStrecke);
|
||||
}
|
||||
@@ -115,6 +136,7 @@ class StreckeUSpurbedingungenState extends State<StreckeUSpurbedingungen> {
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
// Travel distance section header
|
||||
Align(
|
||||
alignment: Alignment.bottomLeft,
|
||||
child: Text(
|
||||
@@ -124,8 +146,10 @@ class StreckeUSpurbedingungenState extends State<StreckeUSpurbedingungen> {
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// Travel distance inputs
|
||||
Row(
|
||||
children: [
|
||||
// Car distance input
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
@@ -145,6 +169,7 @@ class StreckeUSpurbedingungenState extends State<StreckeUSpurbedingungen> {
|
||||
),
|
||||
),
|
||||
|
||||
// Foot distance input
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
@@ -164,6 +189,7 @@ class StreckeUSpurbedingungenState extends State<StreckeUSpurbedingungen> {
|
||||
),
|
||||
),
|
||||
|
||||
// Bicycle distance input
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
@@ -189,6 +215,7 @@ class StreckeUSpurbedingungenState extends State<StreckeUSpurbedingungen> {
|
||||
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Track conditions section header
|
||||
Align(
|
||||
alignment: Alignment.bottomLeft,
|
||||
child: Text(
|
||||
@@ -198,8 +225,10 @@ class StreckeUSpurbedingungenState extends State<StreckeUSpurbedingungen> {
|
||||
),
|
||||
const SizedBox(height: 10,),
|
||||
|
||||
// Track condition inputs
|
||||
Row(
|
||||
children: [
|
||||
// Good conditions input
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
@@ -215,6 +244,7 @@ class StreckeUSpurbedingungenState extends State<StreckeUSpurbedingungen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
// Medium conditions input
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
@@ -230,6 +260,7 @@ class StreckeUSpurbedingungenState extends State<StreckeUSpurbedingungen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
// Poor conditions input
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
|
||||
Reference in New Issue
Block a user