Skip to content

Commit 7f8d21b

Browse files
committed
feat: split controls into VideoPlayerWebOptionsControls
1 parent 0d02f61 commit 7f8d21b

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,36 @@ class VideoPlayerOptions {
401401
class VideoPlayerWebOptions {
402402
/// [VideoPlayerWebOptions] can be optionally used to set additional web settings
403403
const VideoPlayerWebOptions({
404-
this.controlsEnabled = false,
404+
this.controls = const VideoPlayerWebOptionsControls.disabled(),
405+
this.allowContextMenu = true,
406+
});
407+
408+
/// Additional settings how control options are displayed
409+
final VideoPlayerWebOptionsControls controls;
410+
411+
/// Whether context menu (right click) is allowed
412+
final bool allowContextMenu;
413+
}
414+
415+
/// [VideoPlayerWebOptions] can used to set how control options are displayed
416+
@immutable
417+
class VideoPlayerWebOptionsControls {
418+
/// Enabled controls and set how the options are displayed
419+
const VideoPlayerWebOptionsControls.enabled({
405420
this.allowDownload = true,
406421
this.allowFullscreen = true,
407422
this.allowPlaybackRate = true,
408-
this.allowContextMenu = true,
409-
});
423+
}) : enabled = true;
424+
425+
/// Disables control options. Default behavior.
426+
const VideoPlayerWebOptionsControls.disabled()
427+
: enabled = false,
428+
allowDownload = false,
429+
allowFullscreen = false,
430+
allowPlaybackRate = false;
410431

411432
/// Whether native controls are enabled
412-
final bool controlsEnabled;
433+
final bool enabled;
413434

414435
/// Whether downloaded control is displayed
415436
///
@@ -426,9 +447,6 @@ class VideoPlayerWebOptions {
426447
/// Only applicable when [controlsEnabled] is true
427448
final bool allowPlaybackRate;
428449

429-
/// Whether context menu (right click) is allowed
430-
final bool allowContextMenu;
431-
432450
/// A string representation of disallowed controls
433451
String get controlsList {
434452
final List<String> controlsList = <String>[];

packages/video_player/video_player_web/lib/src/video_player.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ class VideoPlayer {
205205

206206
/// Sets control options
207207
Future<void> setOptions(VideoPlayerWebOptions options) async {
208-
if (options.controlsEnabled) {
208+
if (options.controls.enabled) {
209209
_videoElement.controls = true;
210-
final String controlsList = options.controlsList;
210+
final String controlsList = options.controls.controlsList;
211211
if (controlsList.isNotEmpty) {
212212
_videoElement.setAttribute('controlsList', controlsList);
213213
}

0 commit comments

Comments
 (0)