Skip to content

Commit

Permalink
Fullscreen Fixes (#995)
Browse files Browse the repository at this point in the history
* fix navigation pop error by canceling PopScope action if pop is alredy confirmed

* - Refactor PopScope to pop if the player is not in fullscreen instead of always false.
- Remove `Navigator.pop` inside `onPopInvokedWithResult` to avoid issues with external navigation (Example: Pressing dialog barrier, or using an external navigation solution)

* 🎨 formaating fixes

* fix: Full Screen in Landscape mode cut the video #621 (#962)

* Full Screen in Landscape mode cut the video #621

* Full Screen in Landscape mode cut the video #621

---------

Co-authored-by: RaphiTobi <raphael-risse@t-online.de>
Co-authored-by: abulmajd <me@abulmagd.dev>
Co-authored-by: Nhật Long <116779782+longtn-imt@users.noreply.github.com>
  • Loading branch information
4 people committed Sep 20, 2024
1 parent 7b4e615 commit a5e03fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
28 changes: 11 additions & 17 deletions packages/youtube_player_flutter/lib/src/player/youtube_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,23 +295,17 @@ class _YoutubePlayerState extends State<YoutubePlayer> {
fit: StackFit.expand,
clipBehavior: Clip.none,
children: [
Transform.scale(
scale: controller.value.isFullScreen
? (1 / _aspectRatio * MediaQuery.of(context).size.width) /
MediaQuery.of(context).size.height
: 1,
child: RawYoutubePlayer(
key: widget.key,
onEnded: (YoutubeMetaData metaData) {
if (controller.flags.loop) {
controller.load(controller.metadata.videoId,
startAt: controller.flags.startAt,
endAt: controller.flags.endAt);
}

widget.onEnded?.call(metaData);
},
),
RawYoutubePlayer(
key: widget.key,
onEnded: (YoutubeMetaData metaData) {
if (controller.flags.loop) {
controller.load(controller.metadata.videoId,
startAt: controller.flags.startAt,
endAt: controller.flags.endAt);
}

widget.onEnded?.call(metaData);
},
),
if (!controller.flags.hideThumbnail)
AnimatedOpacity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:youtube_player_flutter/youtube_player_flutter.dart';
/// A wrapper for [YoutubePlayer].
class YoutubePlayerBuilder extends StatefulWidget {
/// Builder for [YoutubePlayer] that supports switching between fullscreen and normal mode.
/// When popping, if the player is in fullscreen, fullscreen will be toggled,
/// otherwise the route will pop.
const YoutubePlayerBuilder({
super.key,
required this.player,
Expand Down Expand Up @@ -65,16 +67,18 @@ class _YoutubePlayerBuilderState extends State<YoutubePlayerBuilder>

@override
Widget build(BuildContext context) {
final double height = MediaQuery.of(context).size.height;

final player = Container(
key: playerKey,
height: (MediaQuery.of(context).orientation == Orientation.landscape) ? height : null,
child: PopScope(
canPop: false,
canPop: !widget.player.controller.value.isFullScreen,
onPopInvokedWithResult: (didPop, _) {
if (didPop) return;
final controller = widget.player.controller;
if (controller.value.isFullScreen) {
widget.player.controller.toggleFullScreenMode();
} else {
Navigator.pop(context);
}
},
child: widget.player,
Expand Down

0 comments on commit a5e03fc

Please sign in to comment.