Skip to content

Commit

Permalink
feat(lib): add an API to set controls visibility duration after touch…
Browse files Browse the repository at this point in the history
… or mouse event
  • Loading branch information
ThibaultBee committed Oct 30, 2023
1 parent 82f1d86 commit 84596a8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/src/widgets/apivideo_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ class ApiVideoPlayer extends StatefulWidget {
{super.key,
required this.controller,
this.fit = BoxFit.contain,
this.controlsVisibilityDuration = const Duration(seconds: 4),
this.style,
this.child});

/// Creates a player with api.video style.
factory ApiVideoPlayer.styleFromApiVideo(
{Key? key, required ApiVideoPlayerController controller, Widget? child}) {
{Key? key,
required ApiVideoPlayerController controller,
Duration controlsVisibilityDuration = const Duration(seconds: 4),
Widget? child}) {
return ApiVideoPlayer(
key: key,
controller: controller,
controlsVisibilityDuration: controlsVisibilityDuration,
style: PlayerStyle.defaultStyle,
child: child);
}
Expand All @@ -45,6 +50,9 @@ class ApiVideoPlayer extends StatefulWidget {
/// The controller for the player.
final ApiVideoPlayerController controller;

/// The duration to wait before hiding the controls.
final Duration controlsVisibilityDuration;

/// The style of the player.
final PlayerStyle? style;

Expand All @@ -60,7 +68,8 @@ class ApiVideoPlayer extends StatefulWidget {
}

class _ApiVideoPlayerState extends State<ApiVideoPlayer> {
final _opacityController = TimedOpacityController();
late final _opacityController =
TimedOpacityController(duration: widget.controlsVisibilityDuration);

@override
Widget build(BuildContext context) {
Expand All @@ -77,4 +86,10 @@ class _ApiVideoPlayerState extends State<ApiVideoPlayer> {
_opacityController.showForDuration();
})));
}

@override
void dispose() {
_opacityController.dispose();
super.dispose();
}
}

0 comments on commit 84596a8

Please sign in to comment.