mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-10 19:03:12 +00:00
fix: Handle situation when enum setting from the server has an invalid value
This commit is contained in:
parent
c24e27ce99
commit
4246b50a24
|
@ -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",
|
||||
|
|
|
@ -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!);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue