add radio button to claim generation

This commit is contained in:
2025-06-10 11:09:23 +02:00
parent 949bb7277d
commit f61be23739
2 changed files with 146 additions and 89 deletions

View File

@@ -22,17 +22,32 @@ class MihRadioOptions extends StatefulWidget {
}
class _MihRadioOptionsState extends State<MihRadioOptions> {
late String _currentSelection;
// late String _currentSelection;
@override
void initState() {
super.initState();
setState(() {
_currentSelection = widget.radioOptions[0];
});
if (widget.controller.text.isEmpty && widget.radioOptions.isNotEmpty) {
widget.controller.text = widget.radioOptions[0];
}
// else{
// int index = widget.radioOptions
// .indexWhere((element) => element == option);
// _currentSelection = widget.radioOptions[index];
// widget.controller.text = option;
// }
// _currentSelection = widget.radioOptions[0];
}
Widget displayRadioOptions() {
// The method to handle a change in selection.
void _onChanged(String? value) {
if (value != null) {
widget.controller.text = value;
}
}
Widget displayRadioOptions(String selection) {
return Material(
elevation: 4.0,
borderRadius: BorderRadius.circular(8.0),
@@ -45,12 +60,7 @@ class _MihRadioOptionsState extends State<MihRadioOptions> {
children: widget.radioOptions.map((option) {
return GestureDetector(
onTap: () {
setState(() {
int index = widget.radioOptions
.indexWhere((element) => element == option);
_currentSelection = widget.radioOptions[index];
widget.controller.text = option;
});
_onChanged(option);
},
child: Row(
children: [
@@ -67,13 +77,8 @@ class _MihRadioOptionsState extends State<MihRadioOptions> {
),
Radio<String>(
value: option,
groupValue: _currentSelection,
onChanged: (value) {
setState(() {
_currentSelection = value!;
widget.controller.text = value;
});
},
groupValue: selection,
onChanged: _onChanged,
activeColor: widget.secondaryFillColor,
fillColor: WidgetStateProperty.resolveWith<Color?>(
(Set<WidgetState> states) {
@@ -94,37 +99,42 @@ class _MihRadioOptionsState extends State<MihRadioOptions> {
@override
Widget build(BuildContext context) {
return Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
widget.hintText,
textAlign: TextAlign.left,
style: TextStyle(
color: widget.fillColor,
fontSize: 18,
fontWeight: FontWeight.bold,
return AnimatedBuilder(
animation: widget.controller,
builder: (context, child) {
final currentSelection = widget.controller.text;
return Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
widget.hintText,
textAlign: TextAlign.left,
style: TextStyle(
color: widget.fillColor,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
Visibility(
visible: !widget.requiredText,
child: Text(
"(Optional)",
textAlign: TextAlign.right,
style: TextStyle(
color: widget.fillColor,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
Visibility(
visible: !widget.requiredText,
child: Text(
"(Optional)",
textAlign: TextAlign.right,
style: TextStyle(
color: widget.fillColor,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
],
),
const SizedBox(height: 4),
displayRadioOptions(),
],
);
const SizedBox(height: 4),
displayRadioOptions(currentSelection),
],
);
});
}
}