Files
fforte/lib/screens/excursion/widgets/strecke_u_spurbedingungen.dart
2025-05-27 23:15:33 +02:00

245 lines
7.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:fforte/l10n/app_localizations.dart';
class StreckeUSpurbedingungen extends StatefulWidget {
final TextEditingController kmAutoController;
final TextEditingController kmFussController;
final TextEditingController kmRadController;
final TextEditingController spGutController;
final TextEditingController spMittelController;
final TextEditingController spSchlechtController;
const StreckeUSpurbedingungen({
required this.kmAutoController,
required this.kmFussController,
required this.kmRadController,
required this.spGutController,
required this.spMittelController,
required this.spSchlechtController,
super.key,
});
@override
StreckeUSpurbedingungenState createState() => StreckeUSpurbedingungenState();
}
class StreckeUSpurbedingungenState extends State<StreckeUSpurbedingungen> {
// vars for percent text fields
String carPercent = "0";
String footPercent = "0";
String bikePercent = "0";
String goodPercent = "0";
String middlePercent = "0";
String badPercent = "0";
String totalKm = "0";
@override
void initState() {
super.initState();
// Travle Distance
widget.kmAutoController.addListener(onDistanceTravledUpdated);
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
if (widget.kmAutoController.text == "") {
widget.kmAutoController.text = "0";
widget.kmFussController.text = "0";
widget.kmRadController.text = "0";
}
// Track Conditions
// 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 == "") {
widget.spGutController.text = "0";
widget.spMittelController.text = "0";
widget.spSchlechtController.text = "0";
}
}
void onDistanceTravledUpdated() {
try {
double kmAuto = double.parse(widget.kmAutoController.text);
double kmFuss = double.parse(widget.kmFussController.text);
double kmRad = double.parse(widget.kmRadController.text);
double gesKm = (kmAuto + kmFuss + kmRad);
if (gesKm == 0) {
carPercent = "0";
footPercent = "0";
bikePercent = "0";
} else {
carPercent = (kmAuto / gesKm * 100).round().toString();
footPercent = (kmFuss / gesKm * 100).round().toString();
bikePercent = (kmRad / gesKm * 100).round().toString();
totalKm = gesKm.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 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;
// }
// }
@override
Widget build(BuildContext context) {
return Column(
children: [
Align(
alignment: Alignment.bottomLeft,
child: Text(
"${AppLocalizations.of(context)!.zurueckgelegteStrecke} (km)",
style: Theme.of(context).textTheme.titleMedium,
),
),
const SizedBox(height: 10),
Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Align(
alignment: Alignment.bottomLeft,
child: Text(AppLocalizations.of(context)!.auto),
),
TextField(
keyboardType: TextInputType.number,
controller: widget.kmAutoController,
),
],
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Align(
alignment: Alignment.bottomLeft,
child: Text(AppLocalizations.of(context)!.zuFuss),
),
TextField(
keyboardType: TextInputType.number,
controller: widget.kmFussController,
),
],
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Align(
alignment: Alignment.bottomLeft,
child: Text(AppLocalizations.of(context)!.fahrrad),
),
TextField(
keyboardType: TextInputType.number,
controller: widget.kmRadController,
),
],
),
),
),
const SizedBox(height: 20),
],
),
const SizedBox(height: 20),
Align(
alignment: Alignment.bottomLeft,
child: Text(
"${AppLocalizations.of(context)!.spurbedingungen} (km)",
style: Theme.of(context).textTheme.titleMedium,
),
),
const SizedBox(height: 10,),
Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
children: [
Align(alignment: Alignment.bottomLeft, child: Text(AppLocalizations.of(context)!.gut)),
TextField(
keyboardType: TextInputType.number,
controller: widget.spGutController,
),
],
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
children: [
Align(alignment: Alignment.bottomLeft, child: Text(AppLocalizations.of(context)!.mittel)),
TextField(
keyboardType: TextInputType.number,
controller: widget.spMittelController,
),
],
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
children: [
Align(alignment: Alignment.bottomLeft, child: Text(AppLocalizations.of(context)!.schlecht)),
TextField(
keyboardType: TextInputType.number,
controller: widget.spSchlechtController,
),
],
),
),
),
],
),
],
);
}
}