Uh oh!
There was an error while loading. Please reload this page.
Migrate to Null Safety Flutter V2 - #205
Conversation
mitchross
commented
Mar 16, 2021
solid-software
commented
Mar 16, 2021
Thanks @mitchross - we'll take a look! |
solid-yuriiprykhodko
left a comment
There was a problem hiding this comment.
Great work!
Some minor suggestions added.
I think it makes sense to establish a practice for dealing with nullable variables.
I believe a force-unwrap (variable!) should only occur after the following:
- A non-null assertion.
assert(variable !=null, "This most certainly shouldn't be null!");
variable!.doSmth();- A null-check
if (variable !=null) {
variable!.doSmth();
} else {
// fallback
}- Explicit assignment to the variable:
variable =SurelyNotNull();
variable!.doSmth();Let's make sure we don't have any stray force-unwraps in the code.
| int? get viewId => _viewId; | ||
| /// The viewId for this controller | ||
| int _viewId; | ||
| int? _viewId; |
There was a problem hiding this comment.
Not really sure this has to be nullable.
In any case the code below force-unwraps this variable, and will cause a runtime exception if it happens to be null.
We could:
- Add a non-null assertion to the getter above, and return
intinstead ofint?. - Make the variable
late final.
I'm personally more in favour of option 1, since it feels more runtime-safe.
There was a problem hiding this comment.
Went with late init since the getter is used for testing only. The _viewId comes from the platform itself via
Future onPlatformViewCreated(int viewId) async
| _creatingCompleter = Completer<void>(); | ||
| await vlcPlayerPlatform.create( | ||
| viewId: _viewId, | ||
| viewId: _viewId!, | ||
| uri: dataSource, | ||
| type: dataSourceType, | ||
| package: package, | ||
| hwAcc: hwAcc ?? HwAcc.AUTO, | ||
| autoPlay: autoPlay ?? true, | ||
| hwAcc: hwAcc, | ||
| autoPlay: autoPlay, | ||
| options: options, | ||
| ); | ||
| _creatingCompleter.complete(null); | ||
| _creatingCompleter!.complete(null); |
There was a problem hiding this comment.
We could probably avoid using a Completer here.
Given Future<void>? _viewCreationFuture; is a field in the enclosing class.
_viewCreationFuture = vlcPlayerPlatform.create(
viewId: _viewId,
uri: dataSource,
type: dataSourceType,
package: package,
hwAcc: hwAcc,
autoPlay: autoPlay,
options: options,
);
await _viewCreationFuture;The future can be awaited elsewhere, if necessary.
| isPlaying: event.isPlaying, | ||
| playingState: | ||
| event.isPlaying ? PlayingState.playing : value.playingState, | ||
| event.isPlaying! ? PlayingState.playing : value.playingState, |
There was a problem hiding this comment.
Can we be absolutely sure we're not getting a null here?
| late VoidCallback _listener; | ||
| bool _isInitialized; | ||
| bool? _isInitialized; |
There was a problem hiding this comment.
Can be non-nullable:
| bool? _isInitialized; | |
| bool _isInitialized=false; |
@solid-yuriiprykhodko |
mitchross
commented
Mar 22, 2021
@solid-software any more changes needed? |
solid-software
commented
Mar 22, 2021
@solid-yuriiprykhodko - do you mind giving it another look? |
solid-yuriiprykhodko
left a comment
There was a problem hiding this comment.
Great work on suggestions!
One change requested, after that we should be good to merge.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Yuri Prykhodko <40931732+solid-yuriiprykhodko@users.noreply.github.com>
mitchross
commented
Mar 22, 2021
@solid-pavloprykhodko resolved! For the merge I think because the platform interface package version changed you need to publish that first then the pubsec will resolve. |
solid-software
commented
Mar 22, 2021
thanks @mitchross - amazing contribution! |
NaarGes
commented
Aug 17, 2021
Why it doesn't have null-safe tag on pub.dev? |
I got this error |
solid-software
commented
Aug 17, 2021
@NaarGes please try again, it should be fixed now |
Testing Locally
Change Pubspec
flutter_vlc_player_platform_interface:
path: ../flutter_vlc_player_platform_interface
Migration Strategy