From f3fea9256584f1d30c5cdac3c0ed620c85879e0b Mon Sep 17 00:00:00 2001 From: Bjarte bore Date: Fri, 9 Apr 2021 11:05:48 +0200 Subject: [PATCH] migrated to dart 2.12 with null-safety --- example/lib/background_tasks_counter.dart | 2 +- example/lib/counter.dart | 2 +- example/lib/main.dart | 12 +- example/lib/work_manager_counter.dart | 2 +- example/pubspec.lock | 210 ++++++++++-------- .../background_tasks/background_tasks.dart | 2 +- lib/src/background_tasks/delegate.dart | 6 +- lib/src/background_tasks/models.dart | 16 +- lib/src/callback_dispatcher.dart | 8 +- lib/src/constraints.dart | 10 +- lib/src/models.dart | 26 +-- lib/src/work_manager/delegate.dart | 4 +- lib/src/work_manager/models.dart | 42 ++-- lib/src/work_manager/work_manager.dart | 21 +- pubspec.lock | 137 +++++------- pubspec.yaml | 6 +- test/android_delegate_test.dart | 6 +- test/ios_delegate_test.dart | 4 +- 18 files changed, 247 insertions(+), 269 deletions(-) diff --git a/example/lib/background_tasks_counter.dart b/example/lib/background_tasks_counter.dart index 2ab2312..a5c4106 100644 --- a/example/lib/background_tasks_counter.dart +++ b/example/lib/background_tasks_counter.dart @@ -44,7 +44,7 @@ class BackgroundTasksCounter extends StatelessWidget { ], ), ), - RaisedButton( + TextButton( child: const Text('Count'), onPressed: () => _increaseCounter(snapshot.data), ), diff --git a/example/lib/counter.dart b/example/lib/counter.dart index 98c549c..d0eadcb 100644 --- a/example/lib/counter.dart +++ b/example/lib/counter.dart @@ -44,7 +44,7 @@ class Counter extends StatelessWidget { ], ), ), - RaisedButton( + TextButton( child: const Text('Count'), onPressed: () => _increaseCounter(snapshot.data), ), diff --git a/example/lib/main.dart b/example/lib/main.dart index 4371bbf..b863bc4 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -52,13 +52,13 @@ class MyApp extends StatelessWidget { ), ), const SizedBox(height: 16), - RaisedButton( + TextButton( child: const Text('Counter'), onPressed: () => Navigator.push(context, MaterialPageRoute( builder: (_) => Counter(), )), ), - RaisedButton( + TextButton( child: const Text('Bitcoin price polling'), onPressed: () => Navigator.push(context, MaterialPageRoute( builder: (_) => BtcPrices(), @@ -85,13 +85,13 @@ class MyApp extends StatelessWidget { } List _workManagerExamples(BuildContext context) => [ - RaisedButton( + TextButton( child: const Text('Counter\n(OneTimeWorkRequest)'), onPressed: () => Navigator.push(context, MaterialPageRoute( builder: (_) => WorkManagerCounter(), )), ), - RaisedButton( + TextButton( child: const Text('Bitcoin price polling\n(PeriodicWorkRequest)'), onPressed: () => Navigator.push(context, MaterialPageRoute( builder: (_) => WorkManagerBtcPrices(), @@ -100,7 +100,7 @@ List _workManagerExamples(BuildContext context) => [ ]; List _bgTasksExamples(BuildContext context) => [ - RaisedButton( + TextButton( child: const Text('Counter\n(BGProcessingTaskRequest)'), onPressed: () { Navigator.push(context, MaterialPageRoute( @@ -108,7 +108,7 @@ List _bgTasksExamples(BuildContext context) => [ )); }, ), - RaisedButton( + TextButton( child: const Text('Bitcoin price polling\n(BGAppRefreshTaskRequest)'), onPressed: () { Navigator.push(context, MaterialPageRoute( diff --git a/example/lib/work_manager_counter.dart b/example/lib/work_manager_counter.dart index 65c5577..b2a7d2e 100644 --- a/example/lib/work_manager_counter.dart +++ b/example/lib/work_manager_counter.dart @@ -44,7 +44,7 @@ class WorkManagerCounter extends StatelessWidget { ], ), ), - RaisedButton( + TextButton( child: const Text('Count'), onPressed: () => _increaseCounter(snapshot.data), ), diff --git a/example/pubspec.lock b/example/pubspec.lock index dc0bc54..156671e 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,69 +1,76 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.0.11" - args: - dependency: transitive - description: - name: args - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.5.2" async: dependency: transitive description: name: async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" - charcode: + version: "2.1.0" + characters: dependency: transitive description: - name: charcode - url: "https://pub.flutter-io.cn" + name: characters + url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" - collection: + version: "1.1.0" + charcode: dependency: transitive description: - name: collection - url: "https://pub.flutter-io.cn" + name: charcode + url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" - convert: + version: "1.2.0" + clock: dependency: transitive description: - name: convert - url: "https://pub.flutter-io.cn" + name: clock + url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" - crypto: + version: "1.1.0" + collection: dependency: transitive description: - name: crypto - url: "https://pub.flutter-io.cn" + name: collection + url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.1.3" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.3" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "5.2.1" flt_worker: dependency: "direct dev" description: @@ -85,107 +92,107 @@ packages: dependency: "direct main" description: name: http - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.12.0+4" + version: "0.12.2" http_parser: dependency: transitive description: name: http_parser - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "3.1.3" - image: - dependency: transitive - description: - name: image - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.1.4" + version: "3.1.4" intl: dependency: "direct main" description: name: intl - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.16.1" matcher: dependency: transitive description: name: matcher - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.10" meta: dependency: transitive description: name: meta - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0" path: dependency: transitive description: name: path - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" + version: "1.8.0" path_provider: dependency: "direct main" description: name: path_provider - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" + source: hosted + version: "1.6.27" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" source: hosted - version: "1.6.5" + version: "0.0.1+2" path_provider_macos: dependency: transitive description: name: path_provider_macos - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.0.4" + version: "0.0.4+8" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" - pedantic: + version: "1.0.4" + path_provider_windows: dependency: transitive description: - name: pedantic - url: "https://pub.flutter-io.cn" + name: path_provider_windows + url: "https://pub.dartlang.org" source: hosted - version: "1.9.0" - petitparser: + version: "0.0.4+3" + pedantic: dependency: transitive description: - name: petitparser - url: "https://pub.flutter-io.cn" + name: pedantic + url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "1.9.2" platform: dependency: transitive description: name: platform - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.2.1" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" - quiver: + version: "1.0.3" + process: dependency: transitive description: - name: quiver - url: "https://pub.flutter-io.cn" + name: process + url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "3.0.13" sky_engine: dependency: transitive description: flutter @@ -195,72 +202,79 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.2.15" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0" watcher: dependency: "direct main" description: name: watcher - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.7+15" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" source: hosted - version: "0.9.7+14" - xml: + version: "1.7.4+1" + xdg_directories: dependency: transitive description: - name: xml - url: "https://pub.flutter-io.cn" + name: xdg_directories + url: "https://pub.dartlang.org" source: hosted - version: "3.5.0" + version: "0.1.2" sdks: - dart: ">=2.5.0 <3.0.0" - flutter: ">=1.10.0 <2.0.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.20.0" diff --git a/lib/src/background_tasks/background_tasks.dart b/lib/src/background_tasks/background_tasks.dart index 700b0d2..f39c1fc 100644 --- a/lib/src/background_tasks/background_tasks.dart +++ b/lib/src/background_tasks/background_tasks.dart @@ -8,7 +8,7 @@ export 'models.dart'; /// Schedules a previously registered background task for execution. Future submitTaskRequest(BGTaskRequest request) - => apiChannel.invokeMethod('$METHOD_PREFIX#submitTaskRequest', request.toJson()); + => apiChannel.invokeMethod('$METHOD_PREFIX#submitTaskRequest', request.toJson()) as Future; /// Cancels a scheduled task request with the [identifier]. Future cancelTaskRequest(String identifier) diff --git a/lib/src/background_tasks/delegate.dart b/lib/src/background_tasks/delegate.dart index 194e458..e0b915f 100644 --- a/lib/src/background_tasks/delegate.dart +++ b/lib/src/background_tasks/delegate.dart @@ -13,13 +13,13 @@ Future cancelAllWork() => cancelAllTaskRequests().then((_) => true); @visibleForTesting BGTaskRequest parseWorkIntent(WorkIntent intent) { - bool network; + bool? network; if (intent.constraints?.networkType != null) { - network = intent.constraints.networkType != NetworkType.notRequired; + network = intent.constraints!.networkType != NetworkType.notRequired; } final earliestBeginDate = intent.initialDelay != null - ? DateTime.now().add(intent.initialDelay) : null; + ? DateTime.now().add(intent.initialDelay!) : null; return intent.isProcessingTask == true ? BGProcessingTaskRequest( diff --git a/lib/src/background_tasks/models.dart b/lib/src/background_tasks/models.dart index 5519bdc..31010a8 100644 --- a/lib/src/background_tasks/models.dart +++ b/lib/src/background_tasks/models.dart @@ -14,10 +14,10 @@ abstract class BGTaskRequest { /// /// Setting the property indicates that the background task shouldn’t start any earlier than this date. /// However, the system doesn't guarantee launching the task at the specified date, but only that it won’t begin sooner. - final DateTime earliestBeginDate; + final DateTime? earliestBeginDate; /// Input data of the task. - final Map input; + final Map? input; /// Initializes a [BGTaskRequest] instance with the given [identifier]. /// @@ -43,8 +43,8 @@ class BGAppRefreshTaskRequest extends BGTaskRequest { /// Instantiates a [BGAppRefreshTaskRequest] with the task [identifier] /// and an optional [earliestBeginDate]. const BGAppRefreshTaskRequest(String identifier, { - DateTime earliestBeginDate, - Map input, + DateTime? earliestBeginDate, + Map? input, }) : super(identifier, earliestBeginDate: earliestBeginDate, input: input); } @@ -52,17 +52,17 @@ class BGAppRefreshTaskRequest extends BGTaskRequest { @immutable class BGProcessingTaskRequest extends BGTaskRequest { /// Specifies if the processing task requires a device connected to power. - final bool requiresExternalPower; + final bool? requiresExternalPower; /// Specifies if the processing task requires network connectivity. - final bool requiresNetworkConnectivity; + final bool? requiresNetworkConnectivity; /// Instantiates a [BGProcessingTaskRequest] with the task [identifier]. /// /// and an optional [earliestBeginDate]. const BGProcessingTaskRequest(String identifier, { - DateTime earliestBeginDate, - Map input, + DateTime? earliestBeginDate, + Map? input, this.requiresExternalPower, this.requiresNetworkConnectivity, }) : super(identifier, earliestBeginDate: earliestBeginDate, input: input); diff --git a/lib/src/callback_dispatcher.dart b/lib/src/callback_dispatcher.dart index 57d81c8..462ac2d 100644 --- a/lib/src/callback_dispatcher.dart +++ b/lib/src/callback_dispatcher.dart @@ -18,15 +18,13 @@ void callbackDispatcher() { /// Run the specified function in the background isoloate. Future _executeBackgroundTask(MethodCall call) { final args = call.arguments; - WorkerFn callback; - Map payload; + WorkerFn? callback; + late Map payload; if (args.isNotEmpty) { final handle = CallbackHandle.fromRawHandle(args[0]); payload = Map.castFrom(args[1]); - if (handle != null) { - callback = PluginUtilities.getCallbackFromHandle(handle); - } + callback = PluginUtilities.getCallbackFromHandle(handle) as Future Function(WorkPayload)?; } if (callback != null) { diff --git a/lib/src/constraints.dart b/lib/src/constraints.dart index 560c548..6e1e299 100644 --- a/lib/src/constraints.dart +++ b/lib/src/constraints.dart @@ -8,21 +8,21 @@ class WorkConstraints { /// The default value is dependent on the native `WorkManager`, /// which should be [NetworkType.notRequired] according to /// the [documentation](https://developer.android.com/reference/androidx/work/Constraints.Builder?hl=en#setRequiredNetworkType(androidx.work.NetworkType)). - final NetworkType networkType; + final NetworkType? networkType; /// Whether device battery should be at an acceptable level for the work to run. /// /// The default value is dependent on the native `WorkManager`, /// which should be `false` according to /// the [documentation](https://developer.android.com/reference/androidx/work/Constraints.Builder?hl=en#setRequiresBatteryNotLow(boolean)). - final bool batteryNotLow; + final bool? batteryNotLow; /// Whether device should be charging for the work to run. /// /// The default value is dependent on the native `WorkManager`, /// which should be `false` according to /// the [documentation](https://developer.android.com/reference/androidx/work/Constraints.Builder?hl=en#setRequiresCharging(boolean)). - final bool charging; + final bool? charging; /// Whether device should be idle for the work to run. /// @@ -30,14 +30,14 @@ class WorkConstraints { /// The default value is dependent on the native `WorkManager`, /// which should be `false` according to /// the [documentation](https://developer.android.com/reference/androidx/work/Constraints.Builder?hl=en#setRequiresDeviceIdle(boolean)). - final bool deviceIdle; + final bool? deviceIdle; /// Whether the work requires device's storage should be at an acceptable level. /// /// The default value is dependent on the native `WorkManager`, /// which should be `false` according to /// the [documentation](https://developer.android.com/reference/androidx/work/Constraints.Builder?hl=en#setRequiresStorageNotLow(boolean)). - final bool storageNotLow; + final bool? storageNotLow; /// Creates constraints for a [WorkRequest]. const WorkConstraints({ diff --git a/lib/src/models.dart b/lib/src/models.dart index b5d27c7..cacf2fa 100644 --- a/lib/src/models.dart +++ b/lib/src/models.dart @@ -22,38 +22,38 @@ class WorkIntent { /// Tags for grouping work. /// /// Tags except [identifier] are only available on **Android**. - final Iterable tags; + final Iterable? tags; /// Input data of the work. /// /// Please notice that on iOS, the input data is cached with the key of `identifier`, /// if you schedule a work before the previous one with the same `identifier` is complete, /// cached input of the key `identifier` will be overwritten. - final Map input; + final Map? input; /// The duration of initial delay of the work. - final Duration initialDelay; + final Duration? initialDelay; /// Constraints for the work to run. - final WorkConstraints constraints; + final WorkConstraints? constraints; /// **iOS** only, if `true`, requests to schedule a `BGProcessingTaskRequest`, /// otherwise defaults to `BGAppRefreshTaskRequest`. - final bool isProcessingTask; + final bool? isProcessingTask; /// **Android** only. The repeat interval of a periodic work request. - final Duration repeatInterval; + final Duration? repeatInterval; /// **Android** only. The duration for which the work repeats from the end of the [repeatInterval]. /// /// Note that flex intervals are ignored for certain Android OS versions (in particular, API 23). - final Duration flexInterval; + final Duration? flexInterval; /// Instantiates a [WorkIntent] with an [identifier]. /// /// Optional properties include [tags], [input] data and an [initialDelay]. const WorkIntent({ - @required this.identifier, + required this.identifier, this.tags, this.input, this.initialDelay, @@ -82,20 +82,20 @@ class WorkPayload { final Iterable tags; /// Input of the work. - final Map input; + final Map? input; /// Instantiates the payload for a work. - const WorkPayload._({this.id, this.tags, this.input}); + const WorkPayload._({required this.id, required this.tags, this.input}); /// Decodes the input json into a [WorkPayload]. factory WorkPayload.fromJson(Map json) { Map input = json['input'] ?? {}; - String inputJson = input['data']; - input = inputJson?.isNotEmpty == true ? jsonDecode(inputJson) : {}; + String? inputJson = input['data']; + input = inputJson?.isNotEmpty == true ? jsonDecode(inputJson!) : {}; return WorkPayload._( id: json['id'], tags: Iterable.castFrom(json['tags'] ?? []), - input: input, + input: input as Map?, ); } } diff --git a/lib/src/work_manager/delegate.dart b/lib/src/work_manager/delegate.dart index 9e77cde..09d8a7a 100644 --- a/lib/src/work_manager/delegate.dart +++ b/lib/src/work_manager/delegate.dart @@ -13,7 +13,7 @@ Future wmCancelAllWork() => cancelAllWork(); @visibleForTesting WorkRequest parseWorkIntent(WorkIntent intent) { - final tags = [intent.identifier] + (intent.tags ?? []); + final tags = [intent.identifier] + (intent.tags as List? ?? []); return intent.repeatInterval != null ? PeriodicWorkRequest( @@ -21,7 +21,7 @@ WorkRequest parseWorkIntent(WorkIntent intent) { input: intent.input, initialDelay: intent.initialDelay, constraints: intent.constraints, - repeatInterval: intent.repeatInterval, + repeatInterval: intent.repeatInterval!, flexInterval: intent.flexInterval, ) : OneTimeWorkRequest( diff --git a/lib/src/work_manager/models.dart b/lib/src/work_manager/models.dart index 27f93bd..8650ae1 100644 --- a/lib/src/work_manager/models.dart +++ b/lib/src/work_manager/models.dart @@ -11,19 +11,19 @@ export '../constraints.dart'; @immutable abstract class WorkRequest { /// Tags for grouping work. - final Iterable tags; + final Iterable? tags; /// Input data of the work. - final Map input; + final Map? input; /// The duration of initial delay of the work. - final Duration initialDelay; + final Duration? initialDelay; /// Constraints for the work to run. - final WorkConstraints constraints; + final WorkConstraints? constraints; /// Sets the backoff policy and backoff delay for the work. - final BackoffCriteria backoffCriteria; + final BackoffCriteria? backoffCriteria; /// Instantiates a WorkRequest with optional [tags] and [input] data. /// @@ -56,11 +56,11 @@ class OneTimeWorkRequest extends WorkRequest { /// /// With optional [tags] and [input] data. const OneTimeWorkRequest({ - Iterable tags, - Map input, - Duration initialDelay, - WorkConstraints constraints, - BackoffCriteria backoffCriteria, + Iterable? tags, + Map? input, + Duration? initialDelay, + WorkConstraints? constraints, + BackoffCriteria? backoffCriteria, }) : super( tags: tags, input: input, @@ -79,18 +79,18 @@ class PeriodicWorkRequest extends WorkRequest { /// The duration for which the work repeats from the end of the [repeatInterval]. /// /// Note that flex intervals are ignored for certain OS versions (in particular, API 23). - final Duration flexInterval; + final Duration? flexInterval; /// Creates a [PeriodicWorkRequest] to run periodically once every [repeatInterval] period /// , with an optional [flexInterval]. const PeriodicWorkRequest({ - @required this.repeatInterval, + required this.repeatInterval, this.flexInterval, - Iterable tags, - Map input, - Duration initialDelay, - WorkConstraints constraints, - BackoffCriteria backoffCriteria, + Iterable? tags, + Map? input, + Duration? initialDelay, + WorkConstraints? constraints, + BackoffCriteria? backoffCriteria, }) : super( tags: tags, input: input, @@ -124,14 +124,14 @@ class BackoffCriteria { /// Creates a [BackoffCriteria] with the backoff [policy] and backoff [delay]. const BackoffCriteria({ - @required this.policy, - @required this.delay, + required this.policy, + required this.delay, }); /// Serializes this backoff criteria into a json object. Map toJson() => { - 'policy': policy?.index, - 'delay': delay?.inMicroseconds, + 'policy': policy.index, + 'delay': delay.inMicroseconds, }; } diff --git a/lib/src/work_manager/work_manager.dart b/lib/src/work_manager/work_manager.dart index 742b260..4933709 100644 --- a/lib/src/work_manager/work_manager.dart +++ b/lib/src/work_manager/work_manager.dart @@ -11,33 +11,34 @@ Future enqueueWorkRequest(WorkRequest request) => enqueueWorkRequests([request]); /// Enqueues one or more items for background processing. -Future enqueueWorkRequests(Iterable requests) - => apiChannel.invokeMethod('$METHOD_PREFIX#enqueue', +Future enqueueWorkRequests(Iterable requests) async { + return await apiChannel.invokeMethod('$METHOD_PREFIX#enqueue', requests.map((r) => r.toJson()).toList(growable: false) ); +} /// Cancels all unfinished work with the given [tag]. /// /// Note that cancellation is a best-effort policy and work that is already executing may continue to run. -Future cancelAllWorkByTag(String tag) - => apiChannel.invokeMethod('$METHOD_PREFIX#cancelAllWorkByTag', tag); +Future cancelAllWorkByTag(String tag) async + => await apiChannel.invokeMethod('$METHOD_PREFIX#cancelAllWorkByTag', tag); /// Cancels all unfinished work in the work chain with the given [name]. /// /// Note that cancellation is a best-effort policy and work that is already executing may continue to run. -Future cancelUniqueWork(String name) - => apiChannel.invokeMethod('$METHOD_PREFIX#cancelUniqueWork', name); +Future cancelUniqueWork(String name) async + => await apiChannel.invokeMethod('$METHOD_PREFIX#cancelUniqueWork', name); /// Cancels work with the given [uuid] if it isn't finished. /// /// Note that cancellation is a best-effort policy and work that is already executing may continue to run. -Future cancelWorkById(String uuid) - => apiChannel.invokeMethod('$METHOD_PREFIX#cancelWorkById', uuid); +Future cancelWorkById(String uuid) async + => await apiChannel.invokeMethod('$METHOD_PREFIX#cancelWorkById', uuid); /// Cancels all unfinished work. /// /// **Use this method with extreme caution!** /// By invoking it, you will potentially affect other modules or libraries in your codebase. /// It is strongly recommended that you use one of the other cancellation methods at your disposal. -Future cancelAllWork() - => apiChannel.invokeMethod('$METHOD_PREFIX#cancelAllWork'); +Future cancelAllWork() async + => await apiChannel.invokeMethod('$METHOD_PREFIX#cancelAllWork'); diff --git a/pubspec.lock b/pubspec.lock index c6f84af..24f485c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,62 +1,55 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.0.11" - args: - dependency: transitive - description: - name: args - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.5.2" async: dependency: transitive description: name: async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" charcode: dependency: transitive description: name: charcode - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" - collection: + version: "1.2.0" + clock: dependency: transitive description: - name: collection - url: "https://pub.flutter-io.cn" + name: clock + url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" - convert: + version: "1.1.0" + collection: dependency: transitive description: - name: convert - url: "https://pub.flutter-io.cn" + name: collection + url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" - crypto: + version: "1.15.0" + fake_async: dependency: transitive description: - name: crypto - url: "https://pub.flutter-io.cn" + name: fake_async + url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -67,55 +60,34 @@ packages: description: flutter source: sdk version: "0.0.0" - image: - dependency: transitive - description: - name: image - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.1.4" matcher: dependency: transitive description: name: matcher - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.10" meta: dependency: transitive description: name: meta - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0" path: dependency: transitive description: name: path - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" + version: "1.8.0" pedantic: dependency: "direct dev" description: name: pedantic - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.9.0" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.4.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "1.11.0" sky_engine: dependency: transitive description: flutter @@ -125,65 +97,58 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.2.15" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.0.8" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "3.5.0" + version: "2.1.0" sdks: - dart: ">=2.4.0 <3.0.0" - flutter: ">=1.10.0 <2.0.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.20.0" diff --git a/pubspec.yaml b/pubspec.yaml index 3e528e2..50ad7f7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,8 +5,8 @@ homepage: https://github.com/xinthink/flt_worker/ repository: https://github.com/xinthink/flt_worker/ environment: - sdk: ">=2.3.0 <3.0.0" - flutter: "^1.10.0" + sdk: '>=2.12.0 <3.0.0' + flutter: ">=1.20.0 <2.0.0" dependencies: flutter: @@ -15,7 +15,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - pedantic: ^1.8.0 + pedantic: ^1.11.0 flutter: plugin: diff --git a/test/android_delegate_test.dart b/test/android_delegate_test.dart index 4d3e396..adab80e 100644 --- a/test/android_delegate_test.dart +++ b/test/android_delegate_test.dart @@ -36,7 +36,7 @@ void main() { expect(req, isA()); expect(req.tags, ['work2', 'periodic']); expect((req as PeriodicWorkRequest).repeatInterval, Duration(hours: 4)); - expect((req as PeriodicWorkRequest).flexInterval, Duration(minutes: 1)); + expect(req.flexInterval, Duration(minutes: 1)); }); test('model tranformation with constraints', () { @@ -47,7 +47,7 @@ void main() { constraints: WorkConstraints(), ); var req = parseWorkIntent(intent); - var constraints = req.constraints; + var constraints = req.constraints!; expect(req.initialDelay, Duration(seconds: 59)); expect(constraints, isNotNull); expect(constraints.batteryNotLow, isNull); @@ -67,7 +67,7 @@ void main() { ), ); req = parseWorkIntent(intent); - constraints = req.constraints; + constraints = req.constraints!; expect(constraints.batteryNotLow, isTrue); expect(constraints.charging, isFalse); expect(constraints.deviceIdle, isTrue); diff --git a/test/ios_delegate_test.dart b/test/ios_delegate_test.dart index 2417b91..ae863de 100644 --- a/test/ios_delegate_test.dart +++ b/test/ios_delegate_test.dart @@ -22,7 +22,7 @@ void main() { expect(req, isA()); expect(req.identifier, 'work2'); expect((req as BGProcessingTaskRequest).requiresNetworkConnectivity, isNull); - expect((req as BGProcessingTaskRequest).requiresExternalPower, isNull); + expect(req.requiresExternalPower, isNull); }); test('parse BGProcessingTaskRequest with constraints', () { @@ -38,7 +38,7 @@ void main() { ); var req = parseWorkIntent(intent) as BGProcessingTaskRequest; expect( - (req.earliestBeginDate.millisecondsSinceEpoch - now.add(Duration(minutes: 11)).millisecondsSinceEpoch).abs(), + (req.earliestBeginDate!.millisecondsSinceEpoch - now.add(Duration(minutes: 11)).millisecondsSinceEpoch).abs(), lessThanOrEqualTo(1000)); expect(req.requiresNetworkConnectivity, isTrue); expect(req.requiresExternalPower, isTrue);