enterFullscreen function
Makes the VideoControls present in the current BuildContext enter fullscreen.
Implementation
Future<void> enterFullscreen(BuildContext context) {
return lock.synchronized(() async {
if (!isFullscreen(context)) {
bool playerWasPlaying = player(context).state.playing;
if (context.mounted) {
final stateValue = state(context);
final contextNotifierValue = contextNotifier(context);
final videoViewParametersNotifierValue =
videoViewParametersNotifier(context);
Navigator.of(context, rootNavigator: true).push(
PageRouteBuilder(
pageBuilder: (_, __, ___) => Material(
child: VideoControlsThemeDataInjector(
// NOTE: Make various *VideoControlsThemeData from the parent context available in the fullscreen context.
context: context,
child: VideoStateInheritedWidget(
state: stateValue,
contextNotifier: contextNotifierValue,
videoViewParametersNotifier: videoViewParametersNotifierValue,
disposeNotifiers: false,
child: FullscreenInheritedWidget(
parent: stateValue,
// Another [VideoStateInheritedWidget] inside [FullscreenInheritedWidget] is important to notify about the fullscreen [BuildContext].
child: VideoStateInheritedWidget(
state: stateValue,
contextNotifier: contextNotifierValue,
videoViewParametersNotifier:
videoViewParametersNotifierValue,
disposeNotifiers: false,
child: ValueListenableBuilder<VideoViewParameters>(
valueListenable: videoViewParametersNotifierValue,
builder: (context, videoViewParameters, _) {
return VideoControls(
player:
videoViewParametersNotifierValue.value.player,
// Do not restrict the video's width & height in fullscreen mode:
width: null,
height: null,
fit: videoViewParametersNotifierValue.value.fit,
fill: videoViewParametersNotifierValue.value.fill,
alignment: videoViewParametersNotifierValue
.value.alignment,
aspectRatio: videoViewParametersNotifierValue
.value.aspectRatio,
filterQuality: videoViewParametersNotifierValue
.value.filterQuality,
controls: videoViewParametersNotifierValue
.value.controls,
// Do not acquire or modify existing wakelock in fullscreen mode:
wakelock: false,
pauseUponEnteringBackgroundMode: stateValue
.widget.pauseUponEnteringBackgroundMode,
resumeUponEnteringForegroundMode: stateValue
.widget.resumeUponEnteringForegroundMode,
subtitleViewConfiguration:
videoViewParametersNotifierValue
.value.subtitleViewConfiguration,
onEnterFullscreen:
stateValue.widget.onEnterFullscreen,
onExitFullscreen:
stateValue.widget.onExitFullscreen,
);
}),
),
),
),
),
),
transitionDuration: Duration.zero,
reverseTransitionDuration: Duration.zero,
),
);
await onEnterFullscreen(context)?.call();
if (kIsWeb) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (playerWasPlaying) {
player(context).play();
}
});
}
}
}
});
}