Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ jobs:
run: dart pub publish --dry-run

- name: 📊 Check Code Coverage
uses: VeryGoodOpenSource/very_good_coverage@v2
uses: VeryGoodOpenSource/very_good_coverage@v3
with:
path: "./coverage/lcov.info"
min_coverage: 99
min_coverage: 100

- name: ⬆️ Upload Coverage to Coveralls
uses: coverallsapp/github-action@v2.2.3
Expand Down
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## [3.0.0] - 2024-03-26

### Changed - 3.0.0

* **Dependency**: Updated the `dio` package version from `5.4.1` to `5.4.2`.
* **Dependency**: Updated the `connectivity_plus` plugin from version `^5.0.2` to `^6.0.1`.

### Breaking Changes - 3.0.0

* **SDK and Flutter versions**:
Increased the minimum Dart version from `>=3.0.0 <4.0.0` to `>=3.3.0 <4.0.0` and the Flutter version from `>=3.0.0` to `>=3.19.0` in the `pubspec.yaml` file. This change may affect developers working on older versions of the SDK or Flutter.

### Added - 3.0.0

* **Code Quality**: Enhanced linter rules for improved code quality, enabling previously commented-out linting rules, adding new ones, and notably, the addition of metrics with specific complexity parameters to drive better code practices.

## [2.0.2] - 2024-03-11

Overall, these changes primarily revolve around improving exception handling and string formatting versatility.
Expand Down Expand Up @@ -49,7 +65,7 @@ Overall, these changes primarily revolve around improving exception handling and

## [2.0.0] - 2024-03-10

### Breaking Changes
### Breaking Changes - 2.0.0

Refactor of Exception Handling: The conversion of DioExceptionHandler into a mixin and the static method adjustments represent a breaking change for any existing codebases that instantiate DioExceptionHandler or rely on its previous class structure. Projects will need to update their exception handling implementations to adapt to this refactor. This change aims to streamline the process and enhance overall usability, but will require attention during migration to the new version.

Expand Down
46 changes: 25 additions & 21 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ analyzer:
implicit-casts: false
implicit-dynamic: false

exclude:
- lib/**/*.g.dart
- lib/generated/*.g.dart

# Lint rules and documentation, see http://dart-lang.github.io/linter/lints
linter:
rules:
Expand Down Expand Up @@ -64,7 +68,10 @@ linter:
- prefer_const_literals_to_create_immutables
- prefer_constructors_over_static_methods
- prefer_expression_function_bodies
- prefer_final_fields
- prefer_final_in_for_each
- prefer_final_locals
- prefer_final_parameters
- prefer_foreach
- prefer_single_quotes
# - public_member_api_docs # TODO: Update Docs
Expand All @@ -87,10 +94,10 @@ dart_code_linter:
# - package:dart_code_linter/presets/all.yaml
# - package:dart_code_linter/presets/intl.yaml

# metrics:
# cyclomatic-complexity: 20
# number-of-parameters: 4
# maximum-nesting-level: 5
metrics:
cyclomatic-complexity: 20
number-of-parameters: 4
maximum-nesting-level: 5
metrics-exclude:
- test/**

Expand All @@ -110,22 +117,19 @@ dart_code_linter:
- did-update-widget-method
- dispose-method
# - format-comment: true
- no-magic-number:
allowed: [0, 2, 100, 200, 300, 400, 401, 402, 403, 404, 500, 501, 600]
# - allow-only-once: true
# - avoid-dynamic: true
# - avoid-passing-async-when-sync-expected: true
# - avoid-redundant-async: true
# - avoid-unnecessary-type-assertions: true
# - avoid-unnecessary-type-casts: true
# - avoid-unrelated-type-assertions: true
# - avoid-unused-parameters: true
- avoid-passing-async-when-sync-expected: true
- avoid-redundant-async: true
- avoid-unnecessary-type-assertions: true
- avoid-unnecessary-type-casts: true
- avoid-unrelated-type-assertions: true
- avoid-unused-parameters: true
# - avoid-nested-conditional-expressions: true
# - newline-before-return: true
# - no-boolean-literal-compare: true
# - no-empty-block: true
# - prefer-trailing-comma: true
# - prefer-conditional-expressions: true
# - no-equal-then-else: true
# - prefer-moving-to-variable: true
# - prefer-match-file-name: true
- newline-before-return: true
- no-boolean-literal-compare: true
- no-empty-block: true
- prefer-trailing-comma: true
- prefer-conditional-expressions: true
- no-equal-then-else: true
- prefer-moving-to-variable: true
# - prefer-match-file-name: true
2 changes: 1 addition & 1 deletion example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import Foundation
import connectivity_plus

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
}
34 changes: 17 additions & 17 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ packages:
dependency: transitive
description:
name: connectivity_plus
sha256: "224a77051d52a11fbad53dd57827594d3bd24f945af28bd70bab376d68d437f0"
sha256: e9feae83b1849f61bad9f6f33ee00646e3410d54ce0821e02f262f9901dad3c9
url: "https://pub.dev"
source: hosted
version: "5.0.2"
version: "6.0.1"
connectivity_plus_platform_interface:
dependency: transitive
description:
name: connectivity_plus_platform_interface
sha256: cf1d1c28f4416f8c654d7dc3cd638ec586076255d407cef3ddbdaf178272a71a
sha256: b6a56efe1e6675be240de39107281d4034b64ac23438026355b4234042a35adb
url: "https://pub.dev"
source: hosted
version: "1.2.4"
version: "2.0.0"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -85,10 +85,10 @@ packages:
dependency: "direct main"
description:
name: dio
sha256: "49af28382aefc53562459104f64d16b9dfd1e8ef68c862d5af436cc8356ce5a8"
sha256: "50fec96118958b97c727d0d8f67255d3683f16cc1f90d9bc917b5d4fe3abeca9"
url: "https://pub.dev"
source: hosted
version: "5.4.1"
version: "5.4.2"
equatable:
dependency: transitive
description:
Expand All @@ -103,7 +103,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.0.2"
version: "3.0.0"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -167,14 +167,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.3.0"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
leak_tracker:
dependency: transitive
description:
Expand Down Expand Up @@ -340,6 +332,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "13.0.0"
web:
dependency: transitive
description:
name: web
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
xml:
dependency: transitive
description:
Expand All @@ -349,5 +349,5 @@ packages:
source: hosted
version: "6.5.0"
sdks:
dart: ">=3.3.0-279.1.beta <4.0.0"
flutter: ">=3.10.0"
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.19.0"
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ abstract class ClientExceptionHandler {
/// ExceptionState and parsed data.
///
Future<ResultState<TModel>> callApi<R, TModel>(
ApiHandler<R, TModel> apiHandler, {
HandleHttpParseResponse<R, TModel>? handleHttpParseResponse,
final ApiHandler<R, TModel> apiHandler, {
final HandleHttpParseResponse<R, TModel>? handleHttpParseResponse,
});

/// Method [callApi] is a generic method to handle API calls and return a tuple of
/// ExceptionState and parsed data.
///
static Future<ResultState<TModel>> callApi_<R, TModel>(
ApiHandler<R, TModel> apiHandler, {
HandleHttpParseResponse<R, TModel>? handleHttpParseResponse,
final ApiHandler<R, TModel> apiHandler, {
final HandleHttpParseResponse<R, TModel>? handleHttpParseResponse,
}) async {
throw UnimplementedError();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/exception_handler/dio/dio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
// All rights reserved. Use of this source code
// is governed by a Apache-2.0 license that can be found in the LICENSE file.

export 'dio_exception_handler.dart';
export 'dio_http_response_extension.dart';
export 'exception_handler_dio.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import '../../../exception_handler.dart';
/// any parsing exceptions.
///
Future<ResultState<TModel>> handleHttpGenericParseResponseDio<Response, TModel>(
int statusCode,
ResponseParser<Response, TModel> responseParser,
final int statusCode,
final ResponseParser<Response, TModel> responseParser,
) async {
try {
return FailureState(
Expand Down Expand Up @@ -48,7 +48,7 @@ Future<ResultState<TModel>> handleHttpGenericParseResponseDio<Response, TModel>(
/// Method [handleHttp2xxParseResponseDio] tries to parse the response and handle
/// any parsing exceptions.
Future<ResultState<TModel>> handleHttp2xxParseResponseDio<TModel>(
ResponseParser<Response<Object?>, TModel> responseParser,
final ResponseParser<Response<Object?>, TModel> responseParser,
) async {
try {
final TModel dataModelParsed = await compute(
Expand All @@ -59,7 +59,7 @@ Future<ResultState<TModel>> handleHttp2xxParseResponseDio<TModel>(
return SuccessState(dataModelParsed);
} catch (e) {
try {
// TODO(andgar2010): need more investigation about compute error on platform windows
// TODO(andgar2010): need more investigation about compute error on platform windows.
log(
'''
Handle error compute.
Expand Down Expand Up @@ -123,8 +123,8 @@ class DioExceptionHandler implements ClientExceptionHandler {
/// {@endtemplate}
@override
Future<ResultState<TModel>> callApi<TResponse, TModel>(
ApiHandler<TResponse, TModel> apiHandler, {
HandleHttpParseResponse<TResponse, TModel>? handleHttpParseResponse,
final ApiHandler<TResponse, TModel> apiHandler, {
final HandleHttpParseResponse<TResponse, TModel>? handleHttpParseResponse,
}) async {
handleParseResponse_ = handleHttpParseResponse ??
HandleHttpParseResponse<Response<Object?>, TModel>(
Expand Down Expand Up @@ -167,34 +167,35 @@ class DioExceptionHandler implements ClientExceptionHandler {

/// {@macro DioExceptionHandler_callApi_}
static Future<ResultState<TModel>> callApi_<TResponse, TModel>(
ApiHandler<TResponse, TModel> apiHandler, {
HandleHttpParseResponse<TResponse, TModel>? handleHttpParseResponse,
}) async =>
final ApiHandler<TResponse, TModel> apiHandler, {
final HandleHttpParseResponse<TResponse, TModel>? handleHttpParseResponse,
}) =>
DioExceptionHandler().callApi(
apiHandler,
handleHttpParseResponse: handleHttpParseResponse,
);

/// _isConnected checks the current network connectivity status.
static Future<bool> _isConnected() async {
final ConnectivityResult result = await connectivity.checkConnectivity();
final List<ConnectivityResult> result =
await connectivity.checkConnectivity();

return result != ConnectivityResult.none;
return !result.contains(ConnectivityResult.none);
}

/// _handleHttpResponse processes the HTTP response and handles different
/// status codes.
static Future<ResultState<TModel>> _handleHttpResponse<TModel>(
ResponseParser<Response<Object?>, TModel> responseParser,
final ResponseParser<Response<Object?>, TModel> responseParser,
) async {
final int? statusCode = responseParser.response.statusCode;

return await _handleStatusCode(statusCode, responseParser);
}

static Future<ResultState<TModel>> _handleStatusCode<TModel>(
int? statusCode,
ResponseParser<Response<Object?>, TModel> responseParser,
final int? statusCode,
final ResponseParser<Response<Object?>, TModel> responseParser,
) async =>
// coverage:ignore-start
switch (statusCode) {
Expand Down Expand Up @@ -233,8 +234,8 @@ class DioExceptionHandler implements ClientExceptionHandler {
/// _handleDioException handles exceptions from the Dio library,
/// particularly around connectivity.
static Future<ResultState<TModel>> _handleDioException<TModel>(
DioException e,
StackTrace s,
final DioException e,
final StackTrace s,
) async {
const String start =
'This exception was thrown because the response has a status code of ';
Expand All @@ -249,7 +250,7 @@ class DioExceptionHandler implements ClientExceptionHandler {
ResponseParser(
response: Response(requestOptions: RequestOptions()),
// coverage:ignore-start
parserModel: (_) => Object() as TModel,
parserModel: (final _) => Object() as TModel,
// coverage:ignore-end
exception: e,
stackTrace: s,
Expand Down
14 changes: 7 additions & 7 deletions lib/src/exception_handler/dio/dio_http_response_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import '../../../exception_handler.dart';

/// An extension on `Future<Response>` providing methods for handling Dio HTTP responses and converting them
/// into [ResultState<TModel>] or [ResultState<List<TModel>>] types.
extension HttpResponseDioExtension on Future<Response<Object?>> {
extension DioHttpResponseExtension on Future<Response<Object?>> {
/// Converts a Dio HTTP response into an [ResultState<TModel>] type using
/// a custom `fromJson` method.
///
Expand Down Expand Up @@ -87,12 +87,13 @@ extension HttpResponseDioExtension on Future<Response<Object?>> {
/// ```
///
Future<ResultState<TModel>> fromJson<TModel>(
TModel Function(Map<String, dynamic>) fromJson,
final TModel Function(Map<String, dynamic>) fromJson,
) async =>
await DioExceptionHandler.callApi_<Response<Object?>, TModel>(
ApiHandler(
apiCall: () => this, // Same: response = dio.get('https://').
parserModel: (Object? data) => fromJson(data as Map<String, dynamic>),
parserModel: (final Object? data) =>
fromJson(data as Map<String, dynamic>),
),
);

Expand Down Expand Up @@ -173,14 +174,13 @@ extension HttpResponseDioExtension on Future<Response<Object?>> {
/// }
/// ```
Future<ResultState<List<TModel>>> fromJsonAsList<TModel>(
TModel Function(Map<String, dynamic>) fromJson,
final TModel Function(Map<String, dynamic>) fromJson,
) async =>
await DioExceptionHandler.callApi_<Response<Object?>, List<TModel>>(
ApiHandler(
apiCall: () => this, // Same: response = dio.get('https://').
parserModel: (Object? data) => (data as List<Map<String, dynamic>>)
.map((item) => fromJson(item))
.toList(),
parserModel: (final Object? data) =>
(data as List<Map<String, dynamic>>).map(fromJson).toList(),
),
);
}
Loading