-
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
Put state in Future instead of using Future<isInit> #65
base: PFL-69/align-nullness-with-other-sdks
Are you sure you want to change the base?
Put state in Future instead of using Future<isInit> #65
Conversation
if (tNull is T) { // T is nullable | ||
final jsonStringOrNull = await _invokeMethod<String?>(methodName, data); | ||
if (jsonStringOrNull == null) return tNull; | ||
jsonString = jsonStringOrNull; | ||
} else { | ||
jsonString = await _invokeMethod<String>(methodName, data); | ||
} |
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.
Unrelated to the async stuff. Made the function generic over nullness.
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.
I'm not super fond of that change. Kind of hard to understand and mentally decode IMO. Why do we need it in the first place? In which case was the old implementation not working as expeced?
|
||
_completer.complete(true); |
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.
Completer is used to bridge a callback based API to Future. Given that we are chaining Futures, it is not needed.
}, | ||
), | ||
) | ||
.then((value) { |
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.
Migrated to async method rather than Future chaining.
return EventChannel(name); | ||
static EventChannel registerEventChannel({ | ||
required String name, | ||
void Function(dynamic event)? onEvent, |
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.
Align with registerMethodChannel
: the callback is passed to the register*
function rather than registered in a following call.
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.
lgtm 👍
throw Exception('Error initializing player on native platform side.'); | ||
final String jsonString; | ||
const T? tNull = null; | ||
if (tNull is T) { // T is nullable |
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.
this if
condition is always false
, or do I misunderstand something here?
(you create tNull = null
and in the next line you check for tNull is T
🤔
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.
Nice improvement!
/// Private method channel for this player instance | ||
MethodChannel methodChannel; | ||
|
||
/// Private method channel for this player instance to receive events |
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.
Nit:
/// Private method channel for this player instance to receive events | |
/// Private event channel for this player instance |
if (value == null || value == false) { | ||
_completer.complete(false); | ||
return; | ||
final success = await mainChannel.invokeMethod<bool>( |
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.
Starting from here, the indentation is off. My VSCode is auto-fixing this when I edit this file. Is your IDE maybe configured to indent using 4 spaces?
if (tNull is T) { // T is nullable | ||
final jsonStringOrNull = await _invokeMethod<String?>(methodName, data); | ||
if (jsonStringOrNull == null) return tNull; | ||
jsonString = jsonStringOrNull; | ||
} else { | ||
jsonString = await _invokeMethod<String>(methodName, data); | ||
} |
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.
I'm not super fond of that change. Kind of hard to understand and mentally decode IMO. Why do we need it in the first place? In which case was the old implementation not working as expeced?
static EventChannel registerEventChannel({ | ||
required String name, | ||
void Function(dynamic event)? onEvent, | ||
}) { |
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.
Incorrect indentation. VSCode auto-fixed that when I touched the file
The native player was previously initialized and the communication channels set in a separate async context, with a
Future<bool>
guarding when this was done. This is very similar to how it would be done in C with a condition variable.The safer, and more common in Dart, way is to embed the async result in the future itself. The channels can be safely accessed by
await
ing on the newFuture<NativePlayerHandle>
.This PR depends on: #63