fix: Handle situation when enum setting from the server has an invalid value

This commit is contained in:
Inex Code 2024-07-30 16:40:04 +03:00
parent c24e27ce99
commit 4246b50a24
2 changed files with 41 additions and 23 deletions

View file

@ -373,6 +373,7 @@
},
"settings": "Service settings",
"modified": "Modified",
"invalid_value_detected": "Invalid value detected. Please change it.",
"invalid_input": "Invalid input",
"create_job": "Create job",
"update_job": "Update job",

View file

@ -18,29 +18,46 @@ class BasicEnumConfigItem extends StatefulWidget {
class _BasicEnumConfigItemState extends State<BasicEnumConfigItem> {
@override
Widget build(final BuildContext context) => Column(
children: [
ListTile(
title: Text(widget.configItem.description),
subtitle: (widget.newValue != null &&
widget.newValue != widget.configItem.value)
? Text('service_page.modified'.tr())
: null,
trailing: DropdownButton<String>(
value: widget.newValue ?? widget.configItem.value,
items: widget.configItem.options
.map<DropdownMenuItem<String>>(
(final String option) => DropdownMenuItem<String>(
value: option,
child: Text(option),
),
)
.toList(),
onChanged: (final String? value) {
widget.onChanged(value!);
},
),
Widget build(final BuildContext context) {
final List<DropdownMenuItem<String>> options = widget.configItem.options
.map<DropdownMenuItem<String>>(
(final String option) => DropdownMenuItem<String>(
value: option,
child: Text(option),
),
],
)
.toList();
if (!widget.configItem.options.contains(widget.configItem.value)) {
options.add(
DropdownMenuItem<String>(
value: widget.configItem.value,
enabled: false,
child: Text(widget.configItem.value,
style: Theme.of(context).textTheme.titleMedium!.copyWith(
color: Theme.of(context).colorScheme.error.withOpacity(0.7),
)),
),
);
}
return Column(
children: [
ListTile(
title: Text(widget.configItem.description),
subtitle: (widget.newValue != null &&
widget.newValue != widget.configItem.value)
? Text('service_page.modified'.tr())
: (!widget.configItem.options.contains(widget.configItem.value))
? Text('service_page.invalid_value_detected'.tr())
: null,
trailing: DropdownButton<String>(
value: widget.newValue ?? widget.configItem.value,
items: options,
onChanged: (final String? value) {
widget.onChanged(value!);
},
),
),
],
);
}
}