diff --git a/CHANGELOG.md b/CHANGELOG.md index e6a5997aa..49a7f148a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [Unreleased] +* ⬆️ [#955](https://github.com/fluttercommunity/chewie/pull/955): Add an `F` keyboard shortcut to toggle fullscreen on the desktop controls (respects `allowFullScreen`), complementing the existing `Esc`-to-exit shortcut. Thanks [Ortes](https://github.com/Ortes). + ## [1.14.1] * 🛠️ [#945](https://github.com/fluttercommunity/chewie/pull/945): Flutter 3.38 downgrade. Thanks [diegotori](https://github.com/diegotori). * Library now supports Flutter and Dart versions `3.38.0` and `3.10` or higher respectively, restoring previous compatibility. diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index acdd4a8b0..3f046af20 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -74,6 +74,11 @@ class _MaterialDesktopControlsState extends State if (chewieController.isFullScreen) { _onExpandCollapse(); } + } else if (event is KeyDownEvent && + event.logicalKey == LogicalKeyboardKey.keyF) { + if (chewieController.allowFullScreen) { + _onExpandCollapse(); + } } } diff --git a/test/keyboard_fullscreen_toggle_test.dart b/test/keyboard_fullscreen_toggle_test.dart new file mode 100644 index 000000000..6931bd449 --- /dev/null +++ b/test/keyboard_fullscreen_toggle_test.dart @@ -0,0 +1,60 @@ +import 'package:chewie/chewie.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:video_player/video_player.dart'; + +const _src = + 'https://assets.mixkit.co/videos/preview/mixkit-spinning-around-the-earth-29351-large.mp4'; + +ChewieController _controller({bool allowFullScreen = true}) { + return ChewieController( + videoPlayerController: VideoPlayerController.networkUrl(Uri.parse(_src)), + autoPlay: false, + looping: false, + allowFullScreen: allowFullScreen, + customControls: const MaterialDesktopControls(), + ); +} + +Future _pumpPlayer( + WidgetTester tester, + ChewieController controller, +) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold(body: Chewie(controller: controller)), + ), + ); + await tester.pump(); +} + +Future _pressF(WidgetTester tester) async { + await tester.sendKeyEvent(LogicalKeyboardKey.keyF); + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); +} + +void main() { + testWidgets('F key toggles fullscreen on and off', (tester) async { + final controller = _controller(); + await _pumpPlayer(tester, controller); + expect(controller.isFullScreen, isFalse); + + await _pressF(tester); + expect(controller.isFullScreen, isTrue); + + await _pressF(tester); + expect(controller.isFullScreen, isFalse); + }); + + testWidgets('F key does nothing when allowFullScreen is false', ( + tester, + ) async { + final controller = _controller(allowFullScreen: false); + await _pumpPlayer(tester, controller); + + await _pressF(tester); + expect(controller.isFullScreen, isFalse); + }); +}