Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[video_player] Migrate video player to null safety #3165

Merged
merged 7 commits into from Oct 20, 2020

Conversation

blasten
Copy link

@blasten blasten commented Oct 17, 2020

Migrates video player to null safety.

I made some API changes like the use of Duration.zero/Size.zero instead of null for defaults in VideoPlayerValue and Caption.


/// The total duration of the video.
///
/// Is null when [initialized] is false.
/// The duration is zero if the video hasn't been initialized.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits:

Suggested change
/// The duration is zero if the video hasn't been initialized.
/// The duration is [Duration.zero] if the video hasn't been initialized.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


/// The [size] of the currently loaded video.
///
/// Is null when [initialized] is false.
final Size size;

/// Indicates whether or not the video has been loaded and is ready to play.
bool get initialized => duration != null;
final bool isInitialized;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we need to make this name change? Feels like we can make it as non-breaking as possible?
Although I do agree that isInitialized is a better name. So your call.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

@@ -340,19 +356,18 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
}

@override
// ignore: must_call_super
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove super?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was bad merge. Fixed.

}
_isDisposed = true;
super.dispose();
_lifeCycleObserver.dispose();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the logic here is changed, is it related to null-safety migration?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

if (_isDisposed) {
return;
}
_updatePosition(newPosition);
_updatePosition(newPosition!);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can newPosition here be null?

Copy link
Author

@blasten blasten Oct 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but I changed the code, so it's more readable. The Analyzer can figure out that newPosition! can safely be newPosition if you have a null check earlier.

@@ -545,7 +560,7 @@ class _VideoAppLifeCycleObserver extends Object with WidgetsBindingObserver {
final VideoPlayerController _controller;

void initialize() {
WidgetsBinding.instance.addObserver(this);
WidgetsBinding.instance!.addObserver(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can WidgetsBinding.instance be null?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no. runApp() calls WidgetsFlutterBinding.ensureInitialized().

assetUrl = 'packages/${dataSource.package}/$assetUrl';
}
// 'webOnlyAssetManager' is only in the web version of dart:ui
// ignore: undefined_prefixed_name
assetUrl = ui.webOnlyAssetManager.getAssetUrl(assetUrl);
ui.webOnlyAssetManager.getAssetUrl(assetUrl);
assetUrl = '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why we need this line, could you elaborate?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my mistake. Fixed.

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
2 participants