diff --git a/dio/lib/src/options.dart b/dio/lib/src/options.dart index aa8d2f96d..8631b7135 100644 --- a/dio/lib/src/options.dart +++ b/dio/lib/src/options.dart @@ -99,7 +99,13 @@ mixin OptionsMixin { late String _baseUrl; set baseUrl(String value) { - assert(value.isEmpty || kIsWeb || Uri.parse(value).host.isNotEmpty); + if (value.isNotEmpty && !kIsWeb && Uri.parse(value).host.isEmpty) { + throw ArgumentError.value( + value, + 'baseUrl', + 'Must be a valid URL on platforms other than Web.', + ); + } _baseUrl = value; } diff --git a/dio/test/options_test.dart b/dio/test/options_test.dart index 159e597ed..960029430 100644 --- a/dio/test/options_test.dart +++ b/dio/test/options_test.dart @@ -482,7 +482,7 @@ void main() { if (kIsWeb) 'api/', ]; for (final url in invalidUrls) { - expect(() => BaseOptions(baseUrl: url), throwsA(isA())); + expect(() => BaseOptions(baseUrl: url), throwsA(isA())); } for (final url in validUrls) { expect(BaseOptions(baseUrl: url), isA());