From 9b2b958543427b2457e57a2118a6829259924e6c Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 29 May 2025 15:51:04 +0200 Subject: [PATCH] redone hund u leine removed name field, fixed a bug and fixed value reset error --- lib/screens/excursion/excursion_main.dart | 9 ++- .../excursion/widgets/hund_u_leine.dart | 64 +++++++++++-------- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/lib/screens/excursion/excursion_main.dart b/lib/screens/excursion/excursion_main.dart index a58fdaa..7facc77 100644 --- a/lib/screens/excursion/excursion_main.dart +++ b/lib/screens/excursion/excursion_main.dart @@ -224,13 +224,11 @@ class _ExcursionMainState extends State { required: false, dbDesignation: DatabasesEnum.excursion, ), - const SizedBox(height: 10), + const SizedBox(height: 20), // ---------- Dog(leash) HundULeine( - onMHundChanged: (mHund, mLeine) { - rmap["MHund"]!["controller"]!.text = mHund; - rmap["MLeine"]!["controller"]!.text = mLeine; - }, + mHund: rmap["MHund"]!["controller"]!, + mLeine: rmap["MLeine"]!["controller"]!, ), const SizedBox(height: 10), // ---------- State @@ -391,6 +389,7 @@ class _ExcursionMainState extends State { // welpenAnz: rmap["WelpenAnz"]!["controller"]!, // wpSicher: rmap["WpSicher"]!["controller"]!, ), + const Divider(), const SizedBox(height: 20), // ---------- Counts Anzahlen( diff --git a/lib/screens/excursion/widgets/hund_u_leine.dart b/lib/screens/excursion/widgets/hund_u_leine.dart index 58f1a71..2a817ef 100644 --- a/lib/screens/excursion/widgets/hund_u_leine.dart +++ b/lib/screens/excursion/widgets/hund_u_leine.dart @@ -4,35 +4,45 @@ import 'package:fforte/l10n/app_localizations.dart'; class HundULeine extends StatefulWidget { // 1. with dog (ja, bzw name oder nein) 2. with leash // if nothing selected null - final Function(String, String) onMHundChanged; + final TextEditingController mHund; + final TextEditingController mLeine; - const HundULeine({super.key, required this.onMHundChanged}); + const HundULeine({super.key, required this.mHund, required this.mLeine}); @override HundULeineState createState() => HundULeineState(); } class HundULeineState extends State { - String? _selectedMHundValue; - String _selectedMLeineValue = "nein"; - TextEditingController controller = TextEditingController(); + late String _selectedMHundValue; + late String _selectedMLeineValue; bool visible = false; + @override + void initState() { + if (widget.mHund.text == "") { + _selectedMHundValue = "nein"; + } else { + _selectedMHundValue = widget.mHund.text; + } + + if (widget.mLeine.text == "") { + _selectedMLeineValue = "nein"; + } else { + _selectedMLeineValue = widget.mLeine.text; + } + + super.initState(); + } + void onValueChanged(String mHund, String mLeine) { setState(() { visible = mHund == "ja" ? true : false; _selectedMHundValue = mHund; _selectedMLeineValue = mLeine; + widget.mHund.text = mHund; + widget.mLeine.text = mLeine; }); - - if (mHund != "nein" && controller.text != "") mHund = controller.text; - - if (mHund == "nein") { - _selectedMHundValue = "nein"; - widget.onMHundChanged(mHund, "nein"); - } else { - widget.onMHundChanged(mHund, mLeine); - } } @override @@ -41,7 +51,8 @@ class HundULeineState extends State { children: [ Align( alignment: Alignment.bottomLeft, - child: Text(AppLocalizations.of(context)!.mHund)), + child: Text(AppLocalizations.of(context)!.mHund), + ), ListTile( visualDensity: const VisualDensity(vertical: -4), title: Text(AppLocalizations.of(context)!.ja), @@ -60,20 +71,23 @@ class HundULeineState extends State { value: "nein", groupValue: _selectedMHundValue, onChanged: (value) { - onValueChanged(value!, _selectedMLeineValue); + onValueChanged(value!, "nein"); }, ), ), if (visible) ...[ - TextField( - controller: controller, - onChanged: (value) { - onValueChanged("ja", _selectedMLeineValue); - }, - decoration: - InputDecoration(hintText: AppLocalizations.of(context)!.name), + // TextField( + // controller: controller, + // onChanged: (value) { + // onValueChanged("ja", _selectedMLeineValue); + // }, + // decoration: + // InputDecoration(hintText: AppLocalizations.of(context)!.name), + // ), + Align( + alignment: Alignment.bottomLeft, + child: Text(AppLocalizations.of(context)!.mLeine), ), - Text(AppLocalizations.of(context)!.mLeine), ListTile( visualDensity: const VisualDensity(vertical: -4), title: Text(AppLocalizations.of(context)!.ja), @@ -96,7 +110,7 @@ class HundULeineState extends State { }, ), ), - ] + ], ], ); }