From 685bed5daaf09e9315ac44d3d0fe965f6c71064c Mon Sep 17 00:00:00 2001 From: Ryan Heise Date: Mon, 1 Feb 2021 17:03:53 +1100 Subject: [PATCH] Fix method channel casts. Version 0.1.0-nullsafety.3 --- CHANGELOG.md | 4 ++++ example/pubspec.lock | 2 +- lib/src/android.dart | 7 +++---- lib/src/darwin.dart | 37 ++++++++++++++++--------------------- pubspec.yaml | 2 +- 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f94e443..852939c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.0-nullsafety.3 + +* Fix casts on method channel invocations. + ## 0.1.0-nullsafety.2 * Merge features and bug fixes from 0.0.10 and 0.0.11. diff --git a/example/pubspec.lock b/example/pubspec.lock index 4ed1d1d..6177f1d 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -14,7 +14,7 @@ packages: path: ".." relative: true source: path - version: "0.1.0-nullsafety.2" + version: "0.1.0-nullsafety.3" boolean_selector: dependency: transitive description: diff --git a/lib/src/android.dart b/lib/src/android.dart index f37f10d..2f0007d 100644 --- a/lib/src/android.dart +++ b/lib/src/android.dart @@ -36,13 +36,12 @@ class AndroidAudioManager { Future requestAudioFocus(AndroidAudioFocusRequest focusRequest) async { _onAudioFocusChanged = focusRequest.onAudioFocusChanged; - return await (_channel.invokeMethod( - 'requestAudioFocus', [focusRequest.toJson()]) as FutureOr); + return (await (_channel + .invokeMethod('requestAudioFocus', [focusRequest.toJson()])))!; } Future abandonAudioFocus() async { - return await (_channel.invokeMethod('abandonAudioFocus') - as FutureOr); + return (await (_channel.invokeMethod('abandonAudioFocus')))!; } void close() { diff --git a/lib/src/darwin.dart b/lib/src/darwin.dart index 859ad0a..ac86668 100644 --- a/lib/src/darwin.dart +++ b/lib/src/darwin.dart @@ -74,8 +74,7 @@ class AVAudioSession { _mediaServicesWereResetSubject.stream; Future get category async { - final index = - await (_channel.invokeMethod('getCategory') as FutureOr); + final index = (await (_channel.invokeMethod('getCategory')))!; return AVAudioSessionCategory.values[index]; } @@ -95,14 +94,12 @@ class AVAudioSession { .toList(); Future get categoryOptions async { - final value = await (_channel.invokeMethod('getCategoryOptions') - as FutureOr); + final value = (await (_channel.invokeMethod('getCategoryOptions')))!; return AVAudioSessionCategoryOptions(value); } Future get mode async { - final index = - await (_channel.invokeMethod('getMode') as FutureOr); + final index = (await (_channel.invokeMethod('getMode')))!; return AVAudioSessionMode.values[index]; } @@ -125,29 +122,27 @@ class AVAudioSession { } Future setActive(bool active, - {AVAudioSessionSetActiveOptions? avOptions}) => - _channel.invokeMethod('setActive', [active, avOptions?.value]) - as Future; + {AVAudioSessionSetActiveOptions? avOptions}) async => + (await _channel + .invokeMethod('setActive', [active, avOptions?.value]))!; Future get recordPermission async { - final index = await (_channel.invokeMethod('getRecordPermission') - as FutureOr); + final index = (await (_channel.invokeMethod('getRecordPermission')))!; return AVAudioSessionRecordPermission.values[index]; } - Future requestRecordPermission() => - _channel.invokeMethod('requestRecordPermission') as Future; + Future requestRecordPermission() async => + (await _channel.invokeMethod('requestRecordPermission'))!; - Future get isOtherAudioPlaying => - _channel.invokeMethod('isOtherAudioPlaying') as Future; + Future get isOtherAudioPlaying async => + (await _channel.invokeMethod('isOtherAudioPlaying'))!; - Future get secondaryAudioShouldBeSilencedHint => - _channel.invokeMethod('getSecondaryAudioShouldBeSilencedHint') - as Future; + Future get secondaryAudioShouldBeSilencedHint async => (await _channel + .invokeMethod('getSecondaryAudioShouldBeSilencedHint'))!; - Future get allowHapticsAndSystemSoundsDuringRecording => _channel - .invokeMethod('getAllowHapticsAndSystemSoundsDuringRecording') - as Future; + Future get allowHapticsAndSystemSoundsDuringRecording async => + (await _channel.invokeMethod( + 'getAllowHapticsAndSystemSoundsDuringRecording'))!; Future setAllowHapticsAndSystemSoundsDuringRecording(bool allow) => _channel.invokeMethod( diff --git a/pubspec.yaml b/pubspec.yaml index b188835..1f62fc3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: audio_session description: Sets the iOS audio session category and Android audio attributes for your app, and manages your app's audio focus, mixing and ducking behaviour. -version: 0.1.0-nullsafety.2 +version: 0.1.0-nullsafety.3 homepage: https://github.com/ryanheise/audio_session environment: