-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw on invalid platform return type #62
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3c8e5da
Throw on invalid platform return type
krocard a4535e6
Fix void handled differently by Dart
krocard 034d7f8
Fix comment
krocard f8b4646
Fix comment & remove dead code
krocard d6dd6d8
Add Player's cast methods
krocard 5c67600
Revert "Add Player's cast methods"
krocard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,17 +123,28 @@ class Player with PlayerEventHandler implements PlayerApi { | |
|
||
// Can be used to call methods on the platform side that return a single | ||
// primitive value that is natively supported by the method channel. | ||
Future<T?> _invokeMethod<T>( | ||
Future<T?> _invokeMethodNullable<T>( | ||
String methodName, [ | ||
dynamic data, | ||
]) async { | ||
final result = await _initializationResult; | ||
if (!result) { | ||
return Future.error('Error initializing player on native platform side.'); | ||
throw Exception('Error initializing player on native platform side.'); | ||
} | ||
return _methodChannel.invokeMethod<T>(methodName, _buildPayload(data)); | ||
} | ||
|
||
Future<T> _invokeMethod<T>( | ||
String methodName, [ | ||
dynamic data, | ||
]) async { | ||
final result = await _invokeMethodNullable<T>(methodName, data); | ||
if (result == null) { | ||
throw Exception('Invalid type returned from the native platform side.'); | ||
} | ||
return result; | ||
} | ||
|
||
// Can be used to call methods on the platform side that return a complex | ||
// object that is not natively supported by the method channel. | ||
Future<T?> _invokeObjectMethod<T>( | ||
|
@@ -143,7 +154,7 @@ class Player with PlayerEventHandler implements PlayerApi { | |
]) async { | ||
final result = await _initializationResult; | ||
if (!result) { | ||
return Future.error('Error initializing player on native platform side.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrapping in |
||
throw Exception('Error initializing player on native platform side.'); | ||
} | ||
|
||
final jsonString = await _methodChannel.invokeMethod<String>( | ||
|
@@ -228,31 +239,28 @@ class Player with PlayerEventHandler implements PlayerApi { | |
|
||
@override | ||
Future<double> get currentTime async => | ||
await _invokeMethod<double>(Methods.currentTime) ?? 0.0; | ||
_invokeMethod<double>(Methods.currentTime); | ||
|
||
@override | ||
Future<double> get duration async => | ||
await _invokeMethod<double>(Methods.duration) ?? 0.0; | ||
Future<double> get duration async => _invokeMethod<double>(Methods.duration); | ||
|
||
@override | ||
Future<double> get timeShift async => | ||
await _invokeMethod<double>(Methods.getTimeShift) ?? 0.0; | ||
_invokeMethod<double>(Methods.getTimeShift); | ||
|
||
@override | ||
Future<void> setTimeShift(double timeShift) async => | ||
_invokeMethod<void>(Methods.setTimeShift, timeShift); | ||
|
||
@override | ||
Future<double> get maxTimeShift async => | ||
await _invokeMethod<double>(Methods.maxTimeShift) ?? 0.0; | ||
_invokeMethod<double>(Methods.maxTimeShift); | ||
|
||
@override | ||
Future<bool> get isLive async => | ||
await _invokeMethod<bool>(Methods.isLive) ?? false; | ||
Future<bool> get isLive async => _invokeMethod<bool>(Methods.isLive); | ||
|
||
@override | ||
Future<bool> get isPlaying async => | ||
await _invokeMethod<bool>(Methods.isPlaying) ?? false; | ||
Future<bool> get isPlaying async => _invokeMethod<bool>(Methods.isPlaying); | ||
|
||
@override | ||
Future<List<SubtitleTrack>> get availableSubtitles async => | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also print the method name for better debugging:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done