Validate server URL in settings
This commit is contained in:
parent
13cabaccd1
commit
9b1a502e38
2 changed files with 15 additions and 0 deletions
|
|
@ -10,6 +10,7 @@
|
||||||
"settingsButton": "Change settings",
|
"settingsButton": "Change settings",
|
||||||
"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",
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,20 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result != null && result.isNotEmpty) {
|
if (result != null && result.isNotEmpty) {
|
||||||
|
if (!isInt && 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),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (isInt) {
|
if (isInt) {
|
||||||
final intValue = int.tryParse(result);
|
final intValue = int.tryParse(result);
|
||||||
if (intValue != null) {
|
if (intValue != null) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue