diff --git a/packages/neon/lib/src/pages/login.dart b/packages/neon/lib/src/pages/login.dart index 52a30441..e1f4ee2e 100644 --- a/packages/neon/lib/src/pages/login.dart +++ b/packages/neon/lib/src/pages/login.dart @@ -191,10 +191,18 @@ class _LoginPageState extends State { hintText: 'https://...', ), initialValue: widget.serverURL, - validator: (final input) => validateHttpUrl(context, input), + validator: (final input) => validateHttpUrl( + context, + input, + allowEmptyScheme: true, + ), onFieldSubmitted: (final input) { if (_formKey.currentState!.validate()) { - _loginBloc.setServerURL(input); + var url = input; + if (!(url.startsWith('http://') || url.startsWith('https://'))) { + url = 'http://$url'; + } + _loginBloc.setServerURL(url); } else { _focusNode.requestFocus(); } diff --git a/packages/neon/lib/src/utils/validators.dart b/packages/neon/lib/src/utils/validators.dart index 9d615c8b..3da20514 100644 --- a/packages/neon/lib/src/utils/validators.dart +++ b/packages/neon/lib/src/utils/validators.dart @@ -4,20 +4,24 @@ String? validateHttpUrl( final BuildContext context, final String? input, { final bool httpsOnly = false, + final bool allowEmptyScheme = false, }) { if (input == null || input == '') { return AppLocalizations.of(context).errorInvalidURL; } try { final uri = Uri.parse(input); - // TODO: Maybe make a better error message for http URLs if only https is allowed - if (!(!httpsOnly && (uri.isScheme('http')) || uri.isScheme('https'))) { - return AppLocalizations.of(context).errorInvalidURL; + if (uri.isScheme('https')) { + return null; } - } catch (e) { - return AppLocalizations.of(context).errorInvalidURL; - } - return null; + if (uri.isScheme('http') && !httpsOnly) { + return null; + } + if (uri.isScheme('') && allowEmptyScheme) { + return null; + } + } catch (_) {} + return AppLocalizations.of(context).errorInvalidURL; } String? validateNotEmpty(final BuildContext context, final String? input) {