diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e8ac8d..4225743 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [3.0.1] - 2024-03-26 + +### Fixed - 3.0.1 + +* reverted to using 'isolates.dart' from utils exports to framework for web compatibility. + ## [3.0.0] - 2024-03-26 ### Changed - 3.0.0 diff --git a/lib/exception_handler.dart b/lib/exception_handler.dart index c4539a7..5330906 100644 --- a/lib/exception_handler.dart +++ b/lib/exception_handler.dart @@ -2,6 +2,8 @@ // All rights reserved. Use of this source code // is governed by a Apache-2.0 license that can be found in the LICENSE file. +/// A Dart package for streamlined API handling and robust exception management +/// in Flutter apps. library exception_handler; export 'src/src.dart'; diff --git a/lib/src/exception_handler/dio/dio_exception_handler.dart b/lib/src/exception_handler/dio/dio_exception_handler.dart index 9cb8a8f..2fb7e8f 100644 --- a/lib/src/exception_handler/dio/dio_exception_handler.dart +++ b/lib/src/exception_handler/dio/dio_exception_handler.dart @@ -7,6 +7,7 @@ import 'dart:developer'; import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:dio/dio.dart'; +import 'package:flutter/foundation.dart'; import 'package:http_exception/http_exception.dart'; import 'package:http_status/http_status.dart'; diff --git a/lib/src/utils/isolates/_isolates_io.dart b/lib/src/utils/isolates/_isolates_io.dart deleted file mode 100644 index 5029627..0000000 --- a/lib/src/utils/isolates/_isolates_io.dart +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2014 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// ignore_for_file: prefer_expression_function_bodies, comment_references - -import 'dart:async'; -import 'dart:isolate'; - -import 'constants.dart'; -import 'isolates.dart' as isolates; - -export 'isolates.dart' show ComputeCallback; - -/// The dart:io implementation of [isolate.compute]. -@pragma('vm:prefer-inline') -Future compute( - final isolates.ComputeCallback callback, - final M message, { - String? debugLabel, -}) async { - debugLabel ??= kReleaseMode ? 'compute' : callback.toString(); - - return Isolate.run( - () { - return callback(message); - }, - debugName: debugLabel, - ); -} diff --git a/lib/src/utils/isolates/_isolates_web.dart b/lib/src/utils/isolates/_isolates_web.dart deleted file mode 100644 index c137328..0000000 --- a/lib/src/utils/isolates/_isolates_web.dart +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2014 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// ignore_for_file: comment_references - -import 'isolates.dart' as isolates; - -export 'isolates.dart' show ComputeCallback; - -/// The dart:html implementation of [isolate.compute]. -@pragma('dart2js:tryInline') -Future compute( - final isolates.ComputeCallback callback, - final M message, -) async { - // To avoid blocking the UI immediately for an expensive function call, we - // pump a single frame to allow the framework to complete the current set - // of work. - await null; - - return callback(message); -} diff --git a/lib/src/utils/isolates/constants.dart b/lib/src/utils/isolates/constants.dart deleted file mode 100644 index 60acf87..0000000 --- a/lib/src/utils/isolates/constants.dart +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2014 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/// A constant that is true if the application was compiled in release mode. -/// -/// More specifically, this is a constant that is true if the application was -/// compiled in Dart with the '-Ddart.vm.product=true' flag. -/// -/// Since this is a const value, it can be used to indicate to the compiler that -/// a particular block of code will not be executed in release mode, and hence -/// can be removed. -/// -/// Generally it is better to use [kDebugMode] or `assert` to gate code, since -/// using [kReleaseMode] will introduce differences between release and profile -/// builds, which makes performance testing less representative. -/// -/// See also: -/// -/// * [kDebugMode], which is true in debug builds. -/// * [kProfileMode], which is true in profile builds. -const bool kReleaseMode = bool.fromEnvironment('dart.vm.product'); - -/// A constant that is true if the application was compiled in profile mode. -/// -/// More specifically, this is a constant that is true if the application was -/// compiled in Dart with the '-Ddart.vm.profile=true' flag. -/// -/// Since this is a const value, it can be used to indicate to the compiler that -/// a particular block of code will not be executed in profile mode, an hence -/// can be removed. -/// -/// See also: -/// -/// * [kDebugMode], which is true in debug builds. -/// * [kReleaseMode], which is true in release builds. -const bool kProfileMode = bool.fromEnvironment('dart.vm.profile'); - -/// A constant that is true if the application was compiled in debug mode. -/// -/// More specifically, this is a constant that is true if the application was -/// not compiled with '-Ddart.vm.product=true' and '-Ddart.vm.profile=true'. -/// -/// Since this is a const value, it can be used to indicate to the compiler that -/// a particular block of code will not be executed in debug mode, and hence -/// can be removed. -/// -/// An alternative strategy is to use asserts, as in: -/// -/// ```dart -/// assert(() { -/// // ...debug-only code here... -/// return true; -/// }()); -/// ``` -/// -/// See also: -/// -/// * [kReleaseMode], which is true in release builds. -/// * [kProfileMode], which is true in profile builds. -const bool kDebugMode = !kReleaseMode && !kProfileMode; diff --git a/lib/src/utils/isolates/isolates.dart b/lib/src/utils/isolates/isolates.dart deleted file mode 100644 index 50440c4..0000000 --- a/lib/src/utils/isolates/isolates.dart +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2014 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// ignore_for_file: prefer_expression_function_bodies, comment_references - -import 'dart:async'; - -import '_isolates_io.dart' if (dart.library.js_util) '_isolates_web.dart' - as isolates; - -/// Signature for the callback passed to [compute]. -/// -/// {@macro flutter.foundation.compute.callback} -/// -typedef ComputeCallback = FutureOr Function(M message); - -/// The signature of [compute], which spawns an isolate, runs `callback` on -/// that isolate, passes it `message`, and (eventually) returns the value -/// returned by `callback`. -typedef ComputeImpl = Future Function( - ComputeCallback callback, - M message, { - String? debugLabel, -}); - -/// Asynchronously runs the given [callback] - with the provided [message] - -/// in the background and completes with the result. -/// -/// {@template flutter.foundation.compute.usecase} -/// This is useful for operations that take longer than a few milliseconds, and -/// which would therefore risk skipping frames. For tasks that will only take a -/// few milliseconds, consider [SchedulerBinding.scheduleTask] instead. -/// {@endtemplate} -/// -/// {@youtube 560 315 https://www.youtube.com/watch?v=5AxWC49ZMzs} -/// -/// {@tool snippet} -/// The following code uses the [compute] function to check whether a given -/// integer is a prime number. -/// -/// ```dart -/// Future isPrime(int value) { -/// return compute(_calculate, value); -/// } -/// -/// bool _calculate(int value) { -/// if (value == 1) { -/// return false; -/// } -/// for (int i = 2; i < value; ++i) { -/// if (value % i == 0) { -/// return false; -/// } -/// } -/// return true; -/// } -/// ``` -/// {@end-tool} -/// -/// On web platforms this will run [callback] on the current eventloop. -/// On native platforms this will run [callback] in a separate isolate. -/// -/// {@template flutter.foundation.compute.callback} -/// -/// The `callback`, the `message` given to it as well as the result have to be -/// objects that can be sent across isolates (as they may be transitively copied -/// if needed). The majority of objects can be sent across isolates. -/// -/// See [SendPort.send] for more information about exceptions as well as a note -/// of warning about sending closures, which can capture more state than needed. -/// -/// {@endtemplate} -/// -/// On native platforms `await compute(fun, message)` is equivalent to -/// `await Isolate.run(() => fun(message))`. See also [Isolate.run]. -/// -/// The `debugLabel` - if provided - is used as name for the isolate that -/// executes `callback`. [Timeline] events produced by that isolate will have -/// the name associated with them. This is useful when profiling an application. -Future compute( - final ComputeCallback callback, - final M message, { - final String? debugLabel, -}) { - return isolates.compute(callback, message, debugLabel: debugLabel); -} diff --git a/lib/src/utils/utils.dart b/lib/src/utils/utils.dart index aa8a687..c69034c 100644 --- a/lib/src/utils/utils.dart +++ b/lib/src/utils/utils.dart @@ -3,4 +3,3 @@ // is governed by a Apache-2.0 license that can be found in the LICENSE file. export 'custom_equatable.dart'; -export 'isolates/isolates.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index c904de6..99112bb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: exception_handler description: A Dart package for streamlined API handling and robust exception management in Flutter apps. -version: 3.0.0 +version: 3.0.1 homepage: "https://github.com/andgar2010/exception_handler" environment: