diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2cad43..95dc921 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ on: branches: [main] env: - DART_VERSION: 3.10.4 + DART_VERSION: 3.7.2 jobs: ci: diff --git a/example/main.dart b/example/main.dart index b95faea..b0844dd 100644 --- a/example/main.dart +++ b/example/main.dart @@ -3,9 +3,13 @@ import 'package:sturdy_http/sturdy_http.dart'; void main(List args) async { // Set up some fake HTTP responses using Charlatan - final charlatan = Charlatan() - ..whenGet('/foo', (request) => CharlatanHttpResponse(body: 'Hello World!')) - ..whenPost('/foo', (request) => CharlatanHttpResponse(statusCode: 204)); + final charlatan = + Charlatan() + ..whenGet( + '/foo', + (request) => CharlatanHttpResponse(body: 'Hello World!'), + ) + ..whenPost('/foo', (request) => CharlatanHttpResponse(statusCode: 204)); // Create your client final client = SturdyHttp( diff --git a/lib/src/sturdy_http.dart b/lib/src/sturdy_http.dart index 067f74a..62bccba 100644 --- a/lib/src/sturdy_http.dart +++ b/lib/src/sturdy_http.dart @@ -77,12 +77,13 @@ class SturdyHttp { /// {@macro http_client} SturdyHttp withBaseUrl(String baseUrl) { return SturdyHttp._( - dio: Dio() - ..options.baseUrl = baseUrl - ..options.listFormat = ListFormat.multiCompatible - ..interceptors.addAll(_dio.interceptors) - ..interceptors.removeImplyContentTypeInterceptor() - ..httpClientAdapter = _dio.httpClientAdapter, + dio: + Dio() + ..options.baseUrl = baseUrl + ..options.listFormat = ListFormat.multiCompatible + ..interceptors.addAll(_dio.interceptors) + ..interceptors.removeImplyContentTypeInterceptor() + ..httpClientAdapter = _dio.httpClientAdapter, deserializer: _deserializer, eventListener: _eventListener, retryBehavior: _retryBehavior, @@ -147,9 +148,10 @@ class SturdyHttp { RawRequestBody(:final data) => data, }, queryParameters: request.queryParams, - options: request.options != null - ? request.options!.copyWith(method: request.type.name) - : Options(method: request.type.name), + options: + request.options != null + ? request.options!.copyWith(method: request.type.name) + : Options(method: request.type.name), cancelToken: request.cancelToken, onReceiveProgress: request.onReceiveProgress, onSendProgress: request.onSendProgress, @@ -160,12 +162,13 @@ class SturdyHttp { final data = dioResponse.data; if (data == null || data is! R) { String buildErrorMessage() { - final messageSuffix = data == null - // Disallow empty responses when status code is non-204 - ? 'was null and status code was ${dioResponse!.statusCode}' - // Enforce that response data matches expected, otherwise we'll run into casting - // issues below - : 'was of type ${data.runtimeType} when it should have been of type $R'; + final messageSuffix = + data == null + // Disallow empty responses when status code is non-204 + ? 'was null and status code was ${dioResponse!.statusCode}' + // Enforce that response data matches expected, otherwise we'll run into casting + // issues below + : 'was of type ${data.runtimeType} when it should have been of type $R'; return 'Request to ${request.path} was successful but response data $messageSuffix'; } @@ -272,9 +275,10 @@ Dio _configureDio({ }) { return Dio() // Instruct Dio to use the same Isolate approach as requested of SturdyHttp - ..transformer = deserializer is MainIsolateDeserializer - ? SyncTransformer() - : BackgroundTransformer() + ..transformer = + deserializer is MainIsolateDeserializer + ? SyncTransformer() + : BackgroundTransformer() ..options.baseUrl = baseUrl ..options.listFormat = ListFormat.multiCompatible ..interceptors.addAll(interceptors) diff --git a/pubspec.yaml b/pubspec.yaml index 9ff818a..d968d0d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://github.com/Betterment/sturdy_http repository: https://github.com/Betterment/sturdy_http environment: - sdk: '>=3.10.0 <4.0.0' + sdk: '>=3.7.2 <4.0.0' dependencies: collection: ^1.19.1 @@ -14,5 +14,5 @@ dependencies: dev_dependencies: charlatan: ^0.5.0 - lints: ^6.0.0 - test: ^1.28.0 + lints: ^5.1.1 + test: ^1.29.0 diff --git a/test/src/sturdy_http_test.dart b/test/src/sturdy_http_test.dart index b56c4dd..0378cb6 100644 --- a/test/src/sturdy_http_test.dart +++ b/test/src/sturdy_http_test.dart @@ -338,9 +338,10 @@ void main() { OkResponse(:final response) => Success( Foo.fromMap(response), ), - GenericError() => throw Exception( - 'Decoding error in GenericError', - ), + GenericError() => + throw Exception( + 'Decoding error in GenericError', + ), _ => const Failure('Not expected: orElse'), }; }, @@ -925,22 +926,23 @@ void main() { return CharlatanHttpResponse(statusCode: 522); }); - final response = await buildSubject(retryBehavior: NeverRetry()) - .execute>( - const GetRequest( - defaultPath, - retryBehavior: Retry( - maxRetries: 2, - retryInterval: Duration(milliseconds: 100), - ), - ), - onResponse: (response) { - return switch (response) { - GenericError() => const Success(true), - _ => const Failure('Not expected: orElse'), - }; - }, - ); + final response = await buildSubject( + retryBehavior: NeverRetry(), + ).execute>( + const GetRequest( + defaultPath, + retryBehavior: Retry( + maxRetries: 2, + retryInterval: Duration(milliseconds: 100), + ), + ), + onResponse: (response) { + return switch (response) { + GenericError() => const Success(true), + _ => const Failure('Not expected: orElse'), + }; + }, + ); switch (response) { case Success(:final success): @@ -961,26 +963,27 @@ void main() { return CharlatanHttpResponse(statusCode: statusCode); }); - final response = await buildSubject(retryBehavior: NeverRetry()) - .execute>( - GetRequest( - defaultPath, - retryBehavior: Retry( - maxRetries: 2, - retryInterval: Duration(milliseconds: 100), - retryClause: (r) { - // Body will be `null`; essentially disallow retrying - return r != null; - }, - ), - ), - onResponse: (response) { - return switch (response) { - GenericError() => const Success(true), - _ => const Failure('Not expected: orElse'), - }; + final response = await buildSubject( + retryBehavior: NeverRetry(), + ).execute>( + GetRequest( + defaultPath, + retryBehavior: Retry( + maxRetries: 2, + retryInterval: Duration(milliseconds: 100), + retryClause: (r) { + // Body will be `null`; essentially disallow retrying + return r != null; }, - ); + ), + ), + onResponse: (response) { + return switch (response) { + GenericError() => const Success(true), + _ => const Failure('Not expected: orElse'), + }; + }, + ); switch (response) { case Success(:final success):