finished mHund u mLeine fields

This commit is contained in:
Nico
2024-12-27 20:16:28 +01:00
parent e14cc401ad
commit 1ed257de27
4 changed files with 64 additions and 39 deletions

View File

@@ -2,7 +2,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class HundULeine extends StatefulWidget {
final Function(String) onMHundChanged;
// 1. with dog (ja, bzw name oder nein) 2. with leash
// if nothing selected null
final Function(String, String) onMHundChanged;
const HundULeine({super.key, required this.onMHundChanged});
@@ -11,12 +13,26 @@ class HundULeine extends StatefulWidget {
}
class HundULeineState extends State<HundULeine> {
String? _selectedValue;
String? _selectedMHundValue;
String _selectedMLeineValue = "nein";
TextEditingController controller = TextEditingController();
bool visible = false;
void onChanged(String mHund, String name, String mLeine) {
void onValueChanged(String mHund, String mLeine) {
setState(() {
visible = mHund == "ja" ? true : false;
_selectedMHundValue = mHund;
_selectedMLeineValue = mLeine;
});
if (mHund != "nein" && controller.text != "") mHund = controller.text;
if (mHund == "nein") {
_selectedMHundValue = "nein";
widget.onMHundChanged(mHund, "nein");
} else {
widget.onMHundChanged(mHund, mLeine);
}
}
@override
@@ -29,12 +45,9 @@ class HundULeineState extends State<HundULeine> {
title: Text(AppLocalizations.of(context)!.ja),
leading: Radio<String>(
value: "ja",
groupValue: _selectedValue,
groupValue: _selectedMHundValue,
onChanged: (value) {
setState(() {
_selectedValue = value;
visible = value == "ja" ? true : false;
});
onValueChanged(value!, _selectedMLeineValue);
},
),
),
@@ -43,18 +56,20 @@ class HundULeineState extends State<HundULeine> {
title: Text(AppLocalizations.of(context)!.nein),
leading: Radio<String>(
value: "nein",
groupValue: _selectedValue,
groupValue: _selectedMHundValue,
onChanged: (value) {
setState(() {
_selectedValue = value;
visible = value == "ja" ? true : false;
});
onValueChanged(value!, _selectedMLeineValue);
},
),
),
if (visible) ...[
TextField(
controller: controller,
onChanged: (value) {
onValueChanged("ja", _selectedMLeineValue);
},
decoration:
InputDecoration(hintText: AppLocalizations.of(context)!.name),
),
Text(AppLocalizations.of(context)!.mLeine),
ListTile(
@@ -62,12 +77,9 @@ class HundULeineState extends State<HundULeine> {
title: Text(AppLocalizations.of(context)!.ja),
leading: Radio<String>(
value: "ja",
groupValue: _selectedValue,
groupValue: _selectedMLeineValue,
onChanged: (value) {
setState(() {
_selectedValue = value;
widget.onMHundChanged(value!);
});
onValueChanged("ja", value!);
},
),
),
@@ -76,12 +88,9 @@ class HundULeineState extends State<HundULeine> {
title: Text(AppLocalizations.of(context)!.nein),
leading: Radio<String>(
value: "nein",
groupValue: _selectedValue,
groupValue: _selectedMLeineValue,
onChanged: (value) {
setState(() {
_selectedValue = value;
widget.onMHundChanged(value!);
});
onValueChanged("ja", value!);
},
),
),