diff --git a/example/pubspec.lock b/example/pubspec.lock index 8825e8e..5085c21 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.5.0" bloc: dependency: transitive description: @@ -21,7 +21,7 @@ packages: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" bubble: dependency: "direct main" description: @@ -35,28 +35,28 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: @@ -70,7 +70,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -82,7 +82,7 @@ packages: path: ".." relative: true source: path - version: "0.1.6" + version: "0.2.0-nullsafety.0" flutter_bloc: dependency: "direct main" description: @@ -115,14 +115,14 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" nested: dependency: transitive description: @@ -136,7 +136,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" pedantic: dependency: "direct dev" description: @@ -176,56 +176,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.20.0 <2.0.0" + dart: ">=2.12.0-29.10.beta <3.0.0" + flutter: ">=1.20.0" diff --git a/lib/src/android_config.dart b/lib/src/android_config.dart index e54e855..3f92054 100644 --- a/lib/src/android_config.dart +++ b/lib/src/android_config.dart @@ -1,5 +1,3 @@ -import 'package:flutter/foundation.dart'; - /// Represents the importance of an android notification as described /// under https://developer.android.com/training/notify-user/channels#importance. enum AndroidNotificationImportance { @@ -19,8 +17,7 @@ class AndroidResource { // Optional default resource type to find, if "type/" is not included in the name. Can be null to require an explicit type. final String defType; - const AndroidResource({@required this.name, this.defType = 'drawable'}) - : assert(name != null); + const AndroidResource({required this.name, this.defType = 'drawable'}); } /// Android configuration for the [FlutterBackground] plugin. @@ -51,8 +48,5 @@ class FlutterBackgroundAndroidConfig { this.notificationText = 'Notification text', this.notificationImportance = AndroidNotificationImportance.Default, this.notificationIcon = - const AndroidResource(name: 'ic_launcher', defType: 'mipmap')}) - : assert(notificationTitle != null), - assert(notificationText != null), - assert(notificationImportance != null); + const AndroidResource(name: 'ic_launcher', defType: 'mipmap')}); } diff --git a/lib/src/flutter_background.dart b/lib/src/flutter_background.dart index 363e178..8bfd43d 100644 --- a/lib/src/flutter_background.dart +++ b/lib/src/flutter_background.dart @@ -18,14 +18,14 @@ class FlutterBackground { static Future initialize( {FlutterBackgroundAndroidConfig androidConfig = const FlutterBackgroundAndroidConfig()}) async { - _isInitialized = await _channel.invokeMethod('initialize', { + _isInitialized = await _channel.invokeMethod('initialize', { 'android.notificationTitle': androidConfig.notificationTitle, 'android.notificationText': androidConfig.notificationText, 'android.notificationImportance': _androidNotificationImportanceToInt( androidConfig.notificationImportance), 'android.notificationIconName': androidConfig.notificationIcon.name, 'android.notificationIconDefType': androidConfig.notificationIcon.defType, - }); + }) == true; return _isInitialized; } @@ -34,7 +34,7 @@ class FlutterBackground { /// Returns true, if the user has granted the permission, otherwise false. /// May throw a [PlatformException]. static Future get hasPermissions async { - return await _channel.invokeMethod('hasPermissions') as bool; + return await _channel.invokeMethod('hasPermissions') == true; } /// Enables the execution of the flutter app in the background. @@ -46,9 +46,9 @@ class FlutterBackground { static Future enableBackgroundExecution() async { if (_isInitialized) { final success = - await _channel.invokeMethod('enableBackgroundExecution') as bool; + await _channel.invokeMethod('enableBackgroundExecution'); _isBackgroundExecutionEnabled = true; - return success; + return success == true; } else { throw Exception( 'FlutterBackground plugin must be initialized before calling enableBackgroundExecution()'); @@ -61,11 +61,11 @@ class FlutterBackground { /// Returns true if successful, otherwise false. /// Throws an [Exception] if the plugin is not initialized by calling [FlutterBackground.initialize()] first. /// May throw a [PlatformException]. - static Future disableBackgroundExecution() async { + static Future disableBackgroundExecution() async { if (_isInitialized) { - final success = await _channel.invokeMethod('disableBackgroundExecution'); + final success = await _channel.invokeMethod('disableBackgroundExecution'); _isBackgroundExecutionEnabled = false; - return success; + return success == true; } else { throw Exception( 'FlutterBackground plugin must be initialized before calling disableBackgroundExecution()'); diff --git a/pubspec.lock b/pubspec.lock index c731f2a..90a3fb2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,49 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -66,21 +66,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" pedantic: dependency: "direct dev" description: @@ -99,56 +99,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.20.0 <2.0.0" + dart: ">=2.12.0-29.10.beta <3.0.0" + flutter: ">=1.20.0" diff --git a/pubspec.yaml b/pubspec.yaml index 18ccc57..14cb54a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,11 +1,11 @@ name: flutter_background description: A plugin to keep flutter apps running in the background by using foreground service, wake lock and disabling battery optimizations -version: 0.1.6 +version: 0.2.0-nullsafety.0 repository: https://github.com/JulianAssmann/flutter_background homepage: https://julianassmann.de/ environment: - sdk: ">=2.7.0 <3.0.0" + sdk: ">=2.12.0-29.10.beta <3.0.0" flutter: ">=1.20.0 <2.0.0" dependencies: