136 lines
4.1 KiB
Dart
136 lines
4.1 KiB
Dart
// * Widget for recording presence of dogs and their leash status during excursions
|
|
// * Features:
|
|
// * - Dog presence selection (yes/no)
|
|
// * - Conditional leash status selection
|
|
// * - State persistence via text controllers
|
|
// * - Localized labels
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:fforte/l10n/app_localizations.dart';
|
|
|
|
/// Widget for managing information about dogs during wildlife monitoring
|
|
/// Tracks both presence of dogs and whether they are leashed
|
|
class HundULeine extends StatefulWidget {
|
|
/// Controller for dog presence status (yes/name or no)
|
|
final TextEditingController mHund;
|
|
/// Controller for leash status
|
|
final TextEditingController mLeine;
|
|
|
|
const HundULeine({super.key, required this.mHund, required this.mLeine});
|
|
|
|
@override
|
|
HundULeineState createState() => HundULeineState();
|
|
}
|
|
|
|
/// State class for the dog and leash selection widget
|
|
class HundULeineState extends State<HundULeine> {
|
|
/// Currently selected dog presence value
|
|
late String _selectedMHundValue;
|
|
/// Currently selected leash status value
|
|
late String _selectedMLeineValue;
|
|
/// Whether to show leash selection options
|
|
bool visible = false;
|
|
|
|
@override
|
|
void initState() {
|
|
// Initialize dog presence selection
|
|
if (widget.mHund.text == "") {
|
|
_selectedMHundValue = "nein";
|
|
} else {
|
|
_selectedMHundValue = widget.mHund.text;
|
|
visible = true;
|
|
}
|
|
|
|
// Initialize leash status selection
|
|
if (widget.mLeine.text == "") {
|
|
_selectedMLeineValue = "nein";
|
|
} else {
|
|
_selectedMLeineValue = widget.mLeine.text;
|
|
}
|
|
|
|
super.initState();
|
|
}
|
|
|
|
/// Update widget state and controller values when selections change
|
|
/// @param mHund New dog presence value
|
|
/// @param mLeine New leash status value
|
|
void onValueChanged(String mHund, String mLeine) {
|
|
setState(() {
|
|
visible = mHund == "ja" ? true : false;
|
|
_selectedMHundValue = mHund;
|
|
_selectedMLeineValue = mLeine;
|
|
widget.mHund.text = mHund;
|
|
widget.mLeine.text = mLeine;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
children: [
|
|
// Dog presence section header
|
|
Align(
|
|
alignment: Alignment.bottomLeft,
|
|
child: Text(AppLocalizations.of(context)!.mHund),
|
|
),
|
|
// Dog presence - Yes option
|
|
ListTile(
|
|
visualDensity: const VisualDensity(vertical: -4),
|
|
title: Text(AppLocalizations.of(context)!.ja),
|
|
leading: Radio<String>(
|
|
value: "ja",
|
|
groupValue: _selectedMHundValue,
|
|
onChanged: (value) {
|
|
onValueChanged(value!, _selectedMLeineValue);
|
|
},
|
|
),
|
|
),
|
|
// Dog presence - No option
|
|
ListTile(
|
|
visualDensity: const VisualDensity(vertical: -4),
|
|
title: Text(AppLocalizations.of(context)!.nein),
|
|
leading: Radio<String>(
|
|
value: "nein",
|
|
groupValue: _selectedMHundValue,
|
|
onChanged: (value) {
|
|
onValueChanged(value!, "nein");
|
|
},
|
|
),
|
|
),
|
|
// Conditional leash status section
|
|
if (visible) ...[
|
|
// Leash status section header
|
|
Align(
|
|
alignment: Alignment.bottomLeft,
|
|
child: Text(AppLocalizations.of(context)!.mLeine),
|
|
),
|
|
// Leash status - Yes option
|
|
ListTile(
|
|
visualDensity: const VisualDensity(vertical: -4),
|
|
title: Text(AppLocalizations.of(context)!.ja),
|
|
leading: Radio<String>(
|
|
value: "ja",
|
|
groupValue: _selectedMLeineValue,
|
|
onChanged: (value) {
|
|
onValueChanged("ja", value!);
|
|
},
|
|
),
|
|
),
|
|
// Leash status - No option
|
|
ListTile(
|
|
visualDensity: const VisualDensity(vertical: -4),
|
|
title: Text(AppLocalizations.of(context)!.nein),
|
|
leading: Radio<String>(
|
|
value: "nein",
|
|
groupValue: _selectedMLeineValue,
|
|
onChanged: (value) {
|
|
onValueChanged("ja", value!);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
],
|
|
);
|
|
}
|
|
}
|