Skip to content

Commit e1ab1f1

Browse files
authored
Merge pull request #51 from apivideo/feat/controls_visibility_duration
feat(lib): add an API to set controls visibility duration after touch…
2 parents 84643d4 + 84596a8 commit e1ab1f1

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/src/widgets/apivideo_player.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@ class ApiVideoPlayer extends StatefulWidget {
2323
{super.key,
2424
required this.controller,
2525
this.fit = BoxFit.contain,
26+
this.controlsVisibilityDuration = const Duration(seconds: 4),
2627
this.style,
2728
this.child});
2829

2930
/// Creates a player with api.video style.
3031
factory ApiVideoPlayer.styleFromApiVideo(
31-
{Key? key, required ApiVideoPlayerController controller, Widget? child}) {
32+
{Key? key,
33+
required ApiVideoPlayerController controller,
34+
Duration controlsVisibilityDuration = const Duration(seconds: 4),
35+
Widget? child}) {
3236
return ApiVideoPlayer(
3337
key: key,
3438
controller: controller,
39+
controlsVisibilityDuration: controlsVisibilityDuration,
3540
style: PlayerStyle.defaultStyle,
3641
child: child);
3742
}
@@ -45,6 +50,9 @@ class ApiVideoPlayer extends StatefulWidget {
4550
/// The controller for the player.
4651
final ApiVideoPlayerController controller;
4752

53+
/// The duration to wait before hiding the controls.
54+
final Duration controlsVisibilityDuration;
55+
4856
/// The style of the player.
4957
final PlayerStyle? style;
5058

@@ -60,7 +68,8 @@ class ApiVideoPlayer extends StatefulWidget {
6068
}
6169

6270
class _ApiVideoPlayerState extends State<ApiVideoPlayer> {
63-
final _opacityController = TimedOpacityController();
71+
late final _opacityController =
72+
TimedOpacityController(duration: widget.controlsVisibilityDuration);
6473

6574
@override
6675
Widget build(BuildContext context) {
@@ -77,4 +86,10 @@ class _ApiVideoPlayerState extends State<ApiVideoPlayer> {
7786
_opacityController.showForDuration();
7887
})));
7988
}
89+
90+
@override
91+
void dispose() {
92+
_opacityController.dispose();
93+
super.dispose();
94+
}
8095
}

0 commit comments

Comments
 (0)