mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-02-02 14:16:58 +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",
|
"settings": "Service settings",
|
||||||
"modified": "Modified",
|
"modified": "Modified",
|
||||||
|
"invalid_value_detected": "Invalid value detected. Please change it.",
|
||||||
"invalid_input": "Invalid input",
|
"invalid_input": "Invalid input",
|
||||||
"create_job": "Create job",
|
"create_job": "Create job",
|
||||||
"update_job": "Update job",
|
"update_job": "Update job",
|
||||||
|
|
|
@ -18,24 +18,40 @@ class BasicEnumConfigItem extends StatefulWidget {
|
||||||
|
|
||||||
class _BasicEnumConfigItemState extends State<BasicEnumConfigItem> {
|
class _BasicEnumConfigItemState extends State<BasicEnumConfigItem> {
|
||||||
@override
|
@override
|
||||||
Widget build(final BuildContext context) => Column(
|
Widget build(final BuildContext context) {
|
||||||
children: [
|
final List<DropdownMenuItem<String>> options = widget.configItem.options
|
||||||
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>>(
|
.map<DropdownMenuItem<String>>(
|
||||||
(final String option) => DropdownMenuItem<String>(
|
(final String option) => DropdownMenuItem<String>(
|
||||||
value: option,
|
value: option,
|
||||||
child: Text(option),
|
child: Text(option),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.toList(),
|
.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) {
|
onChanged: (final String? value) {
|
||||||
widget.onChanged(value!);
|
widget.onChanged(value!);
|
||||||
},
|
},
|
||||||
|
@ -43,4 +59,5 @@ class _BasicEnumConfigItemState extends State<BasicEnumConfigItem> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue