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",
|
||||
"statusButton": "Show status",
|
||||
"settingsButton": "Change settings",
|
||||
"invalidValue": "Invalid value",
|
||||
"idLabel": "Device identifier",
|
||||
"urlLabel": "Server URL",
|
||||
"invalidUrlError": "Invalid URL",
|
||||
"accuracyLabel": "Location accuracy",
|
||||
"highAccuracyLabel": "High",
|
||||
"mediumAccuracyLabel": "Medium",
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||
: Preferences.instance.getString(key) ?? '';
|
||||
|
||||
final controller = TextEditingController(text: initialValue);
|
||||
final scaffoldManager = ScaffoldMessenger.of(context);
|
||||
final errorMessage = AppLocalizations.of(context)!.invalidValue;
|
||||
|
||||
final result = await showDialog<String>(
|
||||
context: context,
|
||||
|
|
@ -67,17 +69,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||
);
|
||||
|
||||
if (result != null && result.isNotEmpty) {
|
||||
if (!isInt && key == Preferences.url) {
|
||||
if (key == Preferences.url) {
|
||||
final uri = Uri.tryParse(result);
|
||||
if (uri == null ||
|
||||
uri.host.isEmpty ||
|
||||
!(uri.scheme == 'http' || uri.scheme == 'https')) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content:
|
||||
Text(AppLocalizations.of(context)!.invalidUrlError),
|
||||
),
|
||||
);
|
||||
if (uri == null || uri.host.isEmpty || !(uri.scheme == 'http' || uri.scheme == 'https')) {
|
||||
scaffoldManager.showSnackBar(SnackBar(content: Text(errorMessage)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue