Generalize and fix context
This commit is contained in:
parent
9b1a502e38
commit
15100aaa9c
2 changed files with 6 additions and 11 deletions
|
|
@ -8,9 +8,9 @@
|
||||||
"locationButton": "Send location",
|
"locationButton": "Send location",
|
||||||
"statusButton": "Show status",
|
"statusButton": "Show status",
|
||||||
"settingsButton": "Change settings",
|
"settingsButton": "Change settings",
|
||||||
|
"invalidValue": "Invalid value",
|
||||||
"idLabel": "Device identifier",
|
"idLabel": "Device identifier",
|
||||||
"urlLabel": "Server URL",
|
"urlLabel": "Server URL",
|
||||||
"invalidUrlError": "Invalid URL",
|
|
||||||
"accuracyLabel": "Location accuracy",
|
"accuracyLabel": "Location accuracy",
|
||||||
"highAccuracyLabel": "High",
|
"highAccuracyLabel": "High",
|
||||||
"mediumAccuracyLabel": "Medium",
|
"mediumAccuracyLabel": "Medium",
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||||
: Preferences.instance.getString(key) ?? '';
|
: Preferences.instance.getString(key) ?? '';
|
||||||
|
|
||||||
final controller = TextEditingController(text: initialValue);
|
final controller = TextEditingController(text: initialValue);
|
||||||
|
final scaffoldManager = ScaffoldMessenger.of(context);
|
||||||
|
final errorMessage = AppLocalizations.of(context)!.invalidValue;
|
||||||
|
|
||||||
final result = await showDialog<String>(
|
final result = await showDialog<String>(
|
||||||
context: context,
|
context: context,
|
||||||
|
|
@ -67,17 +69,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result != null && result.isNotEmpty) {
|
if (result != null && result.isNotEmpty) {
|
||||||
if (!isInt && key == Preferences.url) {
|
if (key == Preferences.url) {
|
||||||
final uri = Uri.tryParse(result);
|
final uri = Uri.tryParse(result);
|
||||||
if (uri == null ||
|
if (uri == null || uri.host.isEmpty || !(uri.scheme == 'http' || uri.scheme == 'https')) {
|
||||||
uri.host.isEmpty ||
|
scaffoldManager.showSnackBar(SnackBar(content: Text(errorMessage)));
|
||||||
!(uri.scheme == 'http' || uri.scheme == 'https')) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content:
|
|
||||||
Text(AppLocalizations.of(context)!.invalidUrlError),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue