Merge pull request #1 from traccar/codex/validate-and-show-error-for-server-url
Add URL validation
This commit is contained in:
commit
b143d8c354
2 changed files with 10 additions and 0 deletions
|
|
@ -8,6 +8,7 @@
|
||||||
"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",
|
||||||
"accuracyLabel": "Location accuracy",
|
"accuracyLabel": "Location accuracy",
|
||||||
|
|
|
||||||
|
|
@ -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,6 +69,13 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result != null && result.isNotEmpty) {
|
if (result != null && result.isNotEmpty) {
|
||||||
|
if (key == Preferences.url) {
|
||||||
|
final uri = Uri.tryParse(result);
|
||||||
|
if (uri == null || uri.host.isEmpty || !(uri.scheme == 'http' || uri.scheme == 'https')) {
|
||||||
|
scaffoldManager.showSnackBar(SnackBar(content: Text(errorMessage)));
|
||||||
|
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