From ac808254b57b4e951b293661e980eb294a8e31d6 Mon Sep 17 00:00:00 2001 From: PUNIT Date: Tue, 28 Mar 2023 22:09:42 +0530 Subject: [PATCH 1/5] Added seek forward and rewind buttons --- lib/src/cupertino/cupertino_controls.dart | 84 +++++++++++---- lib/src/material/material_controls.dart | 100 +++++++++++++----- .../material/material_desktop_controls.dart | 100 +++++++++++++----- lib/src/seek_rewind_button.dart | 68 ++++++++++++ 4 files changed, 279 insertions(+), 73 deletions(-) create mode 100644 lib/src/seek_rewind_button.dart diff --git a/lib/src/cupertino/cupertino_controls.dart b/lib/src/cupertino/cupertino_controls.dart index 5626b1481..612c57836 100644 --- a/lib/src/cupertino/cupertino_controls.dart +++ b/lib/src/cupertino/cupertino_controls.dart @@ -12,6 +12,7 @@ import 'package:chewie/src/helpers/utils.dart'; import 'package:chewie/src/models/option_item.dart'; import 'package:chewie/src/models/subtitle_model.dart'; import 'package:chewie/src/notifiers/index.dart'; +import 'package:chewie/src/seek_rewind_button.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -22,12 +23,14 @@ class CupertinoControls extends StatefulWidget { required this.backgroundColor, required this.iconColor, this.showPlayButton = true, + this.showSeekButton = true, Key? key, }) : super(key: key); final Color backgroundColor; final Color iconColor; final bool showPlayButton; + final bool showSeekButton; @override State createState() { @@ -349,25 +352,48 @@ class _CupertinoControlsState extends State final bool isFinished = _latestValue.position >= _latestValue.duration; final bool showPlayButton = widget.showPlayButton && !_latestValue.isPlaying && !_dragging; - - return GestureDetector( - onTap: _latestValue.isPlaying - ? _cancelAndRestartTimer - : () { - _hideTimer?.cancel(); - - setState(() { - notifier.hideStuff = false; - }); - }, - child: CenterPlayButton( - backgroundColor: widget.backgroundColor, - iconColor: widget.iconColor, - isFinished: isFinished, - isPlaying: controller.value.isPlaying, - show: showPlayButton, - onPressed: _playPause, - ), + final bool showSeekButton = + widget.showSeekButton && !_latestValue.isPlaying && !_dragging; + + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SeekRewindButton( + backgroundColor: Colors.black54, + iconColor: Colors.white, + show: showSeekButton, + onPressed: _seekRewind, + onDoublePressed: _seekRewind, + icon: Icons.fast_rewind, + ), + GestureDetector( + onTap: _latestValue.isPlaying + ? _cancelAndRestartTimer + : () { + _hideTimer?.cancel(); + + setState(() { + notifier.hideStuff = false; + }); + }, + child: CenterPlayButton( + backgroundColor: widget.backgroundColor, + iconColor: widget.iconColor, + isFinished: isFinished, + isPlaying: controller.value.isPlaying, + show: showSeekButton, + onPressed: _playPause, + ), + ), + SeekRewindButton( + backgroundColor: Colors.black54, + iconColor: Colors.white, + show: showPlayButton, + onPressed: _seekForward, + onDoublePressed: _seekForward, + icon: Icons.fast_forward, + ), + ], ); } @@ -803,6 +829,26 @@ class _CupertinoControlsState extends State _subtitlesPosition = controller.value.position; }); } + + void _seekForward() { + setState(() { + controller.seekTo( + Duration( + seconds: _latestValue.position.inSeconds + 10, + ), + ); + }); + } + + void _seekRewind() { + setState(() { + controller.seekTo( + Duration( + seconds: _latestValue.position.inSeconds - 10, + ), + ); + }); + } } class _PlaybackSpeedDialog extends StatelessWidget { diff --git a/lib/src/material/material_controls.dart b/lib/src/material/material_controls.dart index 28473b3f3..ea6459572 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -10,6 +10,7 @@ import 'package:chewie/src/material/widgets/playback_speed_dialog.dart'; import 'package:chewie/src/models/option_item.dart'; import 'package:chewie/src/models/subtitle_model.dart'; import 'package:chewie/src/notifiers/index.dart'; +import 'package:chewie/src/seek_rewind_button.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:video_player/video_player.dart'; @@ -17,10 +18,12 @@ import 'package:video_player/video_player.dart'; class MaterialControls extends StatefulWidget { const MaterialControls({ this.showPlayButton = true, + this.showSeekButton = true, Key? key, }) : super(key: key); final bool showPlayButton; + final bool showSeekButton; @override State createState() { @@ -366,33 +369,56 @@ class _MaterialControlsState extends State final bool isFinished = _latestValue.position >= _latestValue.duration; final bool showPlayButton = widget.showPlayButton && !_dragging && !notifier.hideStuff; - - return GestureDetector( - onTap: () { - if (_latestValue.isPlaying) { - if (_displayTapped) { - setState(() { - notifier.hideStuff = true; - }); - } else { - _cancelAndRestartTimer(); - } - } else { - _playPause(); - - setState(() { - notifier.hideStuff = true; - }); - } - }, - child: CenterPlayButton( - backgroundColor: Colors.black54, - iconColor: Colors.white, - isFinished: isFinished, - isPlaying: controller.value.isPlaying, - show: showPlayButton, - onPressed: _playPause, - ), + final bool showSeekButton = + widget.showSeekButton && !_dragging && !notifier.hideStuff; + + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SeekRewindButton( + backgroundColor: Colors.black54, + iconColor: Colors.white, + show: showSeekButton, + onPressed: _seekRewind, + onDoublePressed: _seekRewind, + icon: Icons.fast_rewind, + ), + GestureDetector( + onTap: () { + if (_latestValue.isPlaying) { + if (_displayTapped) { + setState(() { + notifier.hideStuff = true; + }); + } else { + _cancelAndRestartTimer(); + } + } else { + _playPause(); + + setState(() { + notifier.hideStuff = true; + }); + } + }, + child: CenterPlayButton( + backgroundColor: Colors.black54, + iconColor: Colors.white, + isFinished: isFinished, + isPlaying: controller.value.isPlaying, + show: showPlayButton, + onPressed: _playPause, + ), + ), + SeekRewindButton( + backgroundColor: Colors.black54, + iconColor: Colors.white, + show: showSeekButton, + onPressed: _seekForward, + onDoublePressed: _seekForward, + icon: Icons.fast_forward, + ), + ], ); } @@ -542,6 +568,26 @@ class _MaterialControlsState extends State }); } + void _seekForward() { + setState(() { + controller.seekTo( + Duration( + seconds: _latestValue.position.inSeconds + 10, + ), + ); + }); + } + + void _seekRewind() { + setState(() { + controller.seekTo( + Duration( + seconds: _latestValue.position.inSeconds - 10, + ), + ); + }); + } + void _startHideTimer() { final hideControlsTimer = chewieController.hideControlsTimer.isNegative ? ChewieController.defaultHideControlsTimer diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index 8b611c7bb..17754deb1 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -11,6 +11,7 @@ import 'package:chewie/src/material/widgets/playback_speed_dialog.dart'; import 'package:chewie/src/models/option_item.dart'; import 'package:chewie/src/models/subtitle_model.dart'; import 'package:chewie/src/notifiers/index.dart'; +import 'package:chewie/src/seek_rewind_button.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:video_player/video_player.dart'; @@ -18,10 +19,12 @@ import 'package:video_player/video_player.dart'; class MaterialDesktopControls extends StatefulWidget { const MaterialDesktopControls({ this.showPlayButton = true, + this.showSeekButton = true, Key? key, }) : super(key: key); final bool showPlayButton; + final bool showSeekButton; @override State createState() { @@ -330,33 +333,56 @@ class _MaterialDesktopControlsState extends State final bool isFinished = _latestValue.position >= _latestValue.duration; final bool showPlayButton = widget.showPlayButton && !_dragging && !notifier.hideStuff; - - return GestureDetector( - onTap: () { - if (_latestValue.isPlaying) { - if (_displayTapped) { - setState(() { - notifier.hideStuff = true; - }); - } else { - _cancelAndRestartTimer(); - } - } else { - _playPause(); - - setState(() { - notifier.hideStuff = true; - }); - } - }, - child: CenterPlayButton( - backgroundColor: Colors.black54, - iconColor: Colors.white, - isFinished: isFinished, - isPlaying: controller.value.isPlaying, - show: showPlayButton, - onPressed: _playPause, - ), + final bool showSeekButton = + widget.showSeekButton && !_dragging && !notifier.hideStuff; + + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SeekRewindButton( + backgroundColor: Colors.black54, + iconColor: Colors.white, + show: showSeekButton, + onPressed: _seekRewind, + onDoublePressed: _seekRewind, + icon: Icons.fast_rewind, + ), + GestureDetector( + onTap: () { + if (_latestValue.isPlaying) { + if (_displayTapped) { + setState(() { + notifier.hideStuff = true; + }); + } else { + _cancelAndRestartTimer(); + } + } else { + _playPause(); + + setState(() { + notifier.hideStuff = true; + }); + } + }, + child: CenterPlayButton( + backgroundColor: Colors.black54, + iconColor: Colors.white, + isFinished: isFinished, + isPlaying: controller.value.isPlaying, + show: showPlayButton, + onPressed: _playPause, + ), + ), + SeekRewindButton( + backgroundColor: Colors.black54, + iconColor: Colors.white, + show: showSeekButton, + onPressed: _seekForward, + onDoublePressed: _seekForward, + icon: Icons.fast_forward, + ), + ], ); } @@ -593,4 +619,24 @@ class _MaterialDesktopControlsState extends State ), ); } + + void _seekForward() { + setState(() { + controller.seekTo( + Duration( + seconds: _latestValue.position.inSeconds + 10, + ), + ); + }); + } + + void _seekRewind() { + setState(() { + controller.seekTo( + Duration( + seconds: _latestValue.position.inSeconds - 10, + ), + ); + }); + } } diff --git a/lib/src/seek_rewind_button.dart b/lib/src/seek_rewind_button.dart new file mode 100644 index 000000000..a35279c55 --- /dev/null +++ b/lib/src/seek_rewind_button.dart @@ -0,0 +1,68 @@ +import 'package:flutter/material.dart'; + +class SeekRewindButton extends StatefulWidget { + const SeekRewindButton({ + Key? key, + required this.backgroundColor, + this.iconColor, + required this.show, + required this.icon, + this.onPressed, + this.onDoublePressed, + }) : super(key: key); + + final Color backgroundColor; + final Color? iconColor; + final bool show; + final VoidCallback? onPressed; + final VoidCallback? onDoublePressed; + final IconData? icon; + + @override + State createState() => _SeekRewindButtonState(); +} + +class _SeekRewindButtonState extends State + with SingleTickerProviderStateMixin { + late AnimationController animationController; + + @override + void initState() { + super.initState(); + animationController = AnimationController( + vsync: this, + value: 0, + duration: const Duration(milliseconds: 400), + ); + } + + @override + Widget build(BuildContext context) { + return widget.show + ? Expanded( + child: GestureDetector( + onDoubleTap: widget.onDoublePressed, + child: ColoredBox( + color: Colors.transparent, + child: Center( + child: DecoratedBox( + decoration: BoxDecoration( + color: widget.backgroundColor, + shape: BoxShape.circle, + ), + // Always set the iconSize on the IconButton, not on the Icon itself: + // https://github.com/flutter/flutter/issues/52980 + child: IconButton( + iconSize: 32, + padding: const EdgeInsets.all(12.0), + icon: Icon(widget.icon, color: widget.iconColor), + onPressed: widget.onPressed, + ), + ), + ), + ), + ), + ) + : const SizedBox.shrink(); + } +} From e34033c5271f7043a4715d47ce27e2f7a75c6a8f Mon Sep 17 00:00:00 2001 From: punit1111 <128232942+punit1111@users.noreply.github.com> Date: Tue, 28 Mar 2023 22:22:01 +0530 Subject: [PATCH 2/5] Update seek_rewind_button.dart --- lib/src/seek_rewind_button.dart | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/src/seek_rewind_button.dart b/lib/src/seek_rewind_button.dart index a35279c55..30b69dcc7 100644 --- a/lib/src/seek_rewind_button.dart +++ b/lib/src/seek_rewind_button.dart @@ -22,18 +22,11 @@ class SeekRewindButton extends StatefulWidget { State createState() => _SeekRewindButtonState(); } -class _SeekRewindButtonState extends State - with SingleTickerProviderStateMixin { - late AnimationController animationController; +class _SeekRewindButtonState extends State { @override void initState() { super.initState(); - animationController = AnimationController( - vsync: this, - value: 0, - duration: const Duration(milliseconds: 400), - ); } @override From 70a587579ac8e4549263d4945c86a0c49f294ff4 Mon Sep 17 00:00:00 2001 From: punit1111 Date: Tue, 4 Jul 2023 19:28:59 +0530 Subject: [PATCH 3/5] code refactor --- lib/src/cupertino/cupertino_controls.dart | 75 +++++---------- lib/src/hit_area_controls.dart | 64 +++++++++++++ lib/src/material/material_controls.dart | 91 +++++++------------ .../material/material_desktop_controls.dart | 91 +++++++------------ 4 files changed, 155 insertions(+), 166 deletions(-) create mode 100644 lib/src/hit_area_controls.dart diff --git a/lib/src/cupertino/cupertino_controls.dart b/lib/src/cupertino/cupertino_controls.dart index 8ed6509a9..92b03b490 100644 --- a/lib/src/cupertino/cupertino_controls.dart +++ b/lib/src/cupertino/cupertino_controls.dart @@ -9,6 +9,7 @@ import 'package:chewie/src/chewie_progress_colors.dart'; import 'package:chewie/src/cupertino/cupertino_progress_bar.dart'; import 'package:chewie/src/cupertino/widgets/cupertino_options_dialog.dart'; import 'package:chewie/src/helpers/utils.dart'; +import 'package:chewie/src/hit_area_controls.dart'; import 'package:chewie/src/models/option_item.dart'; import 'package:chewie/src/models/subtitle_model.dart'; import 'package:chewie/src/notifiers/index.dart'; @@ -355,45 +356,25 @@ class _CupertinoControlsState extends State final bool showSeekButton = widget.showSeekButton && !_latestValue.isPlaying && !_dragging; - return Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SeekRewindButton( - backgroundColor: Colors.black54, - iconColor: Colors.white, - show: showSeekButton, - onPressed: _seekRewind, - onDoublePressed: _seekRewind, - icon: Icons.fast_rewind, - ), - GestureDetector( - onTap: _latestValue.isPlaying - ? _cancelAndRestartTimer - : () { - _hideTimer?.cancel(); - - setState(() { - notifier.hideStuff = false; - }); - }, - child: CenterPlayButton( - backgroundColor: widget.backgroundColor, - iconColor: widget.iconColor, - isFinished: isFinished, - isPlaying: controller.value.isPlaying, - show: showSeekButton, - onPressed: _playPause, - ), - ), - SeekRewindButton( - backgroundColor: Colors.black54, - iconColor: Colors.white, - show: showPlayButton, - onPressed: _seekForward, - onDoublePressed: _seekForward, - icon: Icons.fast_forward, - ), - ], + return HitAreaControls( + onTapPlay: _latestValue.isPlaying + ? _cancelAndRestartTimer + : () { + _hideTimer?.cancel(); + + setState(() { + notifier.hideStuff = false; + }); + }, + backgroundColor: widget.backgroundColor, + iconColor: widget.iconColor, + isFinished: isFinished, + isPlaying: controller.value.isPlaying, + showPlayButton: showPlayButton, + showSeekButton: showSeekButton, + onPressedPlay: _playPause, + seekRewind: _seekRewind, + seekForward: _seekForward, ); } @@ -833,25 +814,19 @@ class _CupertinoControlsState extends State }); } - void _seekForward() { + void _seekTo({int seconds = 10}) { setState(() { controller.seekTo( Duration( - seconds: _latestValue.position.inSeconds + 10, + seconds: _latestValue.position.inSeconds + seconds, ), ); }); } - void _seekRewind() { - setState(() { - controller.seekTo( - Duration( - seconds: _latestValue.position.inSeconds - 10, - ), - ); - }); - } + void _seekForward() => _seekTo(); + + void _seekRewind() => _seekTo(seconds: -10); } class _PlaybackSpeedDialog extends StatelessWidget { diff --git a/lib/src/hit_area_controls.dart b/lib/src/hit_area_controls.dart new file mode 100644 index 000000000..88f75596b --- /dev/null +++ b/lib/src/hit_area_controls.dart @@ -0,0 +1,64 @@ +import 'package:flutter/material.dart'; + +import 'center_play_button.dart'; +import 'seek_rewind_button.dart'; + +class HitAreaControls extends StatelessWidget { + const HitAreaControls({ + Key? key, + this.onTapPlay, + this.onPressedPlay, + this.seekRewind, + this.seekForward, + required this.backgroundColor, + required this.iconColor, + required this.isFinished, + required this.isPlaying, + required this.showPlayButton, + required this.showSeekButton, + }) : super(key: key); + + final Function()? onTapPlay; + final Function()? onPressedPlay; + final Function()? seekRewind; + final Function()? seekForward; + final Color backgroundColor; + final Color iconColor; + final bool isFinished; + final bool isPlaying; + final bool showPlayButton; + final bool showSeekButton; + + @override + Widget build(BuildContext context) { + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + _buildSeekRewindButton(isSeekForward: false), + GestureDetector( + onTap: onTapPlay, + child: CenterPlayButton( + backgroundColor: backgroundColor, + iconColor: iconColor, + isFinished: isFinished, + isPlaying: isPlaying, + show: showPlayButton, + onPressed: onPressedPlay, + ), + ), + _buildSeekRewindButton(isSeekForward: true), + ], + ); + } + + SeekRewindButton _buildSeekRewindButton({bool isSeekForward = true}) { + return SeekRewindButton( + backgroundColor: backgroundColor, + iconColor: iconColor, + show: showSeekButton, + onPressed: isSeekForward ? seekForward : seekRewind, + onDoublePressed: isSeekForward ? seekForward : seekRewind, + icon: isSeekForward ? Icons.fast_forward : Icons.fast_rewind, + ); + } +} diff --git a/lib/src/material/material_controls.dart b/lib/src/material/material_controls.dart index 6a859a82a..3f6a9b85b 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -4,6 +4,7 @@ import 'package:chewie/src/center_play_button.dart'; import 'package:chewie/src/chewie_player.dart'; import 'package:chewie/src/chewie_progress_colors.dart'; import 'package:chewie/src/helpers/utils.dart'; +import 'package:chewie/src/hit_area_controls.dart'; import 'package:chewie/src/material/material_progress_bar.dart'; import 'package:chewie/src/material/widgets/options_dialog.dart'; import 'package:chewie/src/material/widgets/playback_speed_dialog.dart'; @@ -372,53 +373,33 @@ class _MaterialControlsState extends State final bool showSeekButton = widget.showSeekButton && !_dragging && !notifier.hideStuff; - return Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SeekRewindButton( - backgroundColor: Colors.black54, - iconColor: Colors.white, - show: showSeekButton, - onPressed: _seekRewind, - onDoublePressed: _seekRewind, - icon: Icons.fast_rewind, - ), - GestureDetector( - onTap: () { - if (_latestValue.isPlaying) { - if (_displayTapped) { - setState(() { - notifier.hideStuff = true; - }); - } else { - _cancelAndRestartTimer(); - } - } else { - _playPause(); - - setState(() { - notifier.hideStuff = true; - }); - } - }, - child: CenterPlayButton( - backgroundColor: Colors.black54, - iconColor: Colors.white, - isFinished: isFinished, - isPlaying: controller.value.isPlaying, - show: showPlayButton, - onPressed: _playPause, - ), - ), - SeekRewindButton( - backgroundColor: Colors.black54, - iconColor: Colors.white, - show: showSeekButton, - onPressed: _seekForward, - onDoublePressed: _seekForward, - icon: Icons.fast_forward, - ), - ], + return HitAreaControls( + onTapPlay: () { + if (_latestValue.isPlaying) { + if (_displayTapped) { + setState(() { + notifier.hideStuff = true; + }); + } else { + _cancelAndRestartTimer(); + } + } else { + _playPause(); + + setState(() { + notifier.hideStuff = true; + }); + } + }, + backgroundColor: Colors.black54, + iconColor: Colors.white, + isFinished: isFinished, + isPlaying: controller.value.isPlaying, + showPlayButton: showPlayButton, + showSeekButton: showSeekButton, + onPressedPlay: _playPause, + seekRewind: _seekRewind, + seekForward: _seekForward, ); } @@ -568,25 +549,19 @@ class _MaterialControlsState extends State }); } - void _seekForward() { + void _seekTo({int seconds = 10}) { setState(() { controller.seekTo( Duration( - seconds: _latestValue.position.inSeconds + 10, + seconds: _latestValue.position.inSeconds + seconds, ), ); }); } - void _seekRewind() { - setState(() { - controller.seekTo( - Duration( - seconds: _latestValue.position.inSeconds - 10, - ), - ); - }); - } + void _seekForward() => _seekTo(); + + void _seekRewind() => _seekTo(seconds: -10); void _startHideTimer() { final hideControlsTimer = chewieController.hideControlsTimer.isNegative diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index a3d3c6f64..19bd280fc 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -5,6 +5,7 @@ import 'package:chewie/src/center_play_button.dart'; import 'package:chewie/src/chewie_player.dart'; import 'package:chewie/src/chewie_progress_colors.dart'; import 'package:chewie/src/helpers/utils.dart'; +import 'package:chewie/src/hit_area_controls.dart'; import 'package:chewie/src/material/material_progress_bar.dart'; import 'package:chewie/src/material/widgets/options_dialog.dart'; import 'package:chewie/src/material/widgets/playback_speed_dialog.dart'; @@ -336,53 +337,33 @@ class _MaterialDesktopControlsState extends State final bool showSeekButton = widget.showSeekButton && !_dragging && !notifier.hideStuff; - return Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SeekRewindButton( - backgroundColor: Colors.black54, - iconColor: Colors.white, - show: showSeekButton, - onPressed: _seekRewind, - onDoublePressed: _seekRewind, - icon: Icons.fast_rewind, - ), - GestureDetector( - onTap: () { - if (_latestValue.isPlaying) { - if (_displayTapped) { - setState(() { - notifier.hideStuff = true; - }); - } else { - _cancelAndRestartTimer(); - } - } else { - _playPause(); - - setState(() { - notifier.hideStuff = true; - }); - } - }, - child: CenterPlayButton( - backgroundColor: Colors.black54, - iconColor: Colors.white, - isFinished: isFinished, - isPlaying: controller.value.isPlaying, - show: showPlayButton, - onPressed: _playPause, - ), - ), - SeekRewindButton( - backgroundColor: Colors.black54, - iconColor: Colors.white, - show: showSeekButton, - onPressed: _seekForward, - onDoublePressed: _seekForward, - icon: Icons.fast_forward, - ), - ], + return HitAreaControls( + onTapPlay: () { + if (_latestValue.isPlaying) { + if (_displayTapped) { + setState(() { + notifier.hideStuff = true; + }); + } else { + _cancelAndRestartTimer(); + } + } else { + _playPause(); + + setState(() { + notifier.hideStuff = true; + }); + } + }, + backgroundColor: Colors.black54, + iconColor: Colors.white, + isFinished: isFinished, + isPlaying: controller.value.isPlaying, + showPlayButton: showPlayButton, + showSeekButton: showSeekButton, + onPressedPlay: _playPause, + seekRewind: _seekRewind, + seekForward: _seekForward, ); } @@ -623,23 +604,17 @@ class _MaterialDesktopControlsState extends State ); } - void _seekForward() { + void _seekTo({int seconds = 10}) { setState(() { controller.seekTo( Duration( - seconds: _latestValue.position.inSeconds + 10, + seconds: _latestValue.position.inSeconds + seconds, ), ); }); } - void _seekRewind() { - setState(() { - controller.seekTo( - Duration( - seconds: _latestValue.position.inSeconds - 10, - ), - ); - }); - } + void _seekForward() => _seekTo(); + + void _seekRewind() => _seekTo(seconds: -10); } From ca7a04f258ddde08b013757e58353b2f15752b4b Mon Sep 17 00:00:00 2001 From: punit1111 Date: Sat, 5 Aug 2023 11:48:22 +0530 Subject: [PATCH 4/5] fixed changes --- lib/src/cupertino/cupertino_controls.dart | 2 - lib/src/hit_area_controls.dart | 47 ++++++++++--------- lib/src/material/material_controls.dart | 2 - .../material/material_desktop_controls.dart | 2 - ...d_button.dart => seek_control_button.dart} | 23 +++++---- 5 files changed, 36 insertions(+), 40 deletions(-) rename lib/src/{seek_rewind_button.dart => seek_control_button.dart} (76%) diff --git a/lib/src/cupertino/cupertino_controls.dart b/lib/src/cupertino/cupertino_controls.dart index 92b03b490..b3624db84 100644 --- a/lib/src/cupertino/cupertino_controls.dart +++ b/lib/src/cupertino/cupertino_controls.dart @@ -3,7 +3,6 @@ import 'dart:math' as math; import 'dart:ui' as ui; import 'package:chewie/src/animated_play_pause.dart'; -import 'package:chewie/src/center_play_button.dart'; import 'package:chewie/src/chewie_player.dart'; import 'package:chewie/src/chewie_progress_colors.dart'; import 'package:chewie/src/cupertino/cupertino_progress_bar.dart'; @@ -13,7 +12,6 @@ import 'package:chewie/src/hit_area_controls.dart'; import 'package:chewie/src/models/option_item.dart'; import 'package:chewie/src/models/subtitle_model.dart'; import 'package:chewie/src/notifiers/index.dart'; -import 'package:chewie/src/seek_rewind_button.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; diff --git a/lib/src/hit_area_controls.dart b/lib/src/hit_area_controls.dart index 88f75596b..b1e96c294 100644 --- a/lib/src/hit_area_controls.dart +++ b/lib/src/hit_area_controls.dart @@ -1,15 +1,15 @@ import 'package:flutter/material.dart'; import 'center_play_button.dart'; -import 'seek_rewind_button.dart'; +import 'seek_control_button.dart'; class HitAreaControls extends StatelessWidget { const HitAreaControls({ Key? key, - this.onTapPlay, - this.onPressedPlay, - this.seekRewind, - this.seekForward, + required this.onTapPlay, + required this.onPressedPlay, + required this.seekRewind, + required this.seekForward, required this.backgroundColor, required this.iconColor, required this.isFinished, @@ -18,10 +18,10 @@ class HitAreaControls extends StatelessWidget { required this.showSeekButton, }) : super(key: key); - final Function()? onTapPlay; - final Function()? onPressedPlay; - final Function()? seekRewind; - final Function()? seekForward; + final VoidCallback onTapPlay; + final VoidCallback onPressedPlay; + final VoidCallback seekRewind; + final VoidCallback seekForward; final Color backgroundColor; final Color iconColor; final bool isFinished; @@ -34,7 +34,14 @@ class HitAreaControls extends StatelessWidget { return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - _buildSeekRewindButton(isSeekForward: false), + SeekControlButton( + backgroundColor: backgroundColor, + iconColor: iconColor, + show: showSeekButton, + onPressed: seekRewind, + onDoublePressed: seekRewind, + icon: Icons.fast_rewind, + ), GestureDetector( onTap: onTapPlay, child: CenterPlayButton( @@ -46,19 +53,15 @@ class HitAreaControls extends StatelessWidget { onPressed: onPressedPlay, ), ), - _buildSeekRewindButton(isSeekForward: true), + SeekControlButton( + backgroundColor: backgroundColor, + iconColor: iconColor, + show: showSeekButton, + onPressed: seekForward, + onDoublePressed: seekForward, + icon: Icons.fast_forward, + ), ], ); } - - SeekRewindButton _buildSeekRewindButton({bool isSeekForward = true}) { - return SeekRewindButton( - backgroundColor: backgroundColor, - iconColor: iconColor, - show: showSeekButton, - onPressed: isSeekForward ? seekForward : seekRewind, - onDoublePressed: isSeekForward ? seekForward : seekRewind, - icon: isSeekForward ? Icons.fast_forward : Icons.fast_rewind, - ); - } } diff --git a/lib/src/material/material_controls.dart b/lib/src/material/material_controls.dart index 3f6a9b85b..0729130e6 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -1,6 +1,5 @@ import 'dart:async'; -import 'package:chewie/src/center_play_button.dart'; import 'package:chewie/src/chewie_player.dart'; import 'package:chewie/src/chewie_progress_colors.dart'; import 'package:chewie/src/helpers/utils.dart'; @@ -11,7 +10,6 @@ import 'package:chewie/src/material/widgets/playback_speed_dialog.dart'; import 'package:chewie/src/models/option_item.dart'; import 'package:chewie/src/models/subtitle_model.dart'; import 'package:chewie/src/notifiers/index.dart'; -import 'package:chewie/src/seek_rewind_button.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:video_player/video_player.dart'; diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index 19bd280fc..ea4b1e80d 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'package:chewie/src/animated_play_pause.dart'; -import 'package:chewie/src/center_play_button.dart'; import 'package:chewie/src/chewie_player.dart'; import 'package:chewie/src/chewie_progress_colors.dart'; import 'package:chewie/src/helpers/utils.dart'; @@ -12,7 +11,6 @@ import 'package:chewie/src/material/widgets/playback_speed_dialog.dart'; import 'package:chewie/src/models/option_item.dart'; import 'package:chewie/src/models/subtitle_model.dart'; import 'package:chewie/src/notifiers/index.dart'; -import 'package:chewie/src/seek_rewind_button.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:video_player/video_player.dart'; diff --git a/lib/src/seek_rewind_button.dart b/lib/src/seek_control_button.dart similarity index 76% rename from lib/src/seek_rewind_button.dart rename to lib/src/seek_control_button.dart index 30b69dcc7..9cd5c1294 100644 --- a/lib/src/seek_rewind_button.dart +++ b/lib/src/seek_control_button.dart @@ -1,29 +1,28 @@ import 'package:flutter/material.dart'; -class SeekRewindButton extends StatefulWidget { - const SeekRewindButton({ +class SeekControlButton extends StatefulWidget { + const SeekControlButton({ Key? key, required this.backgroundColor, - this.iconColor, + required this.iconColor, required this.show, required this.icon, - this.onPressed, - this.onDoublePressed, + required this.onPressed, + required this.onDoublePressed, }) : super(key: key); final Color backgroundColor; - final Color? iconColor; + final Color iconColor; final bool show; - final VoidCallback? onPressed; - final VoidCallback? onDoublePressed; - final IconData? icon; + final VoidCallback onPressed; + final VoidCallback onDoublePressed; + final IconData icon; @override - State createState() => _SeekRewindButtonState(); + State createState() => _SeekControlButtonState(); } -class _SeekRewindButtonState extends State { - +class _SeekControlButtonState extends State { @override void initState() { super.initState(); From e9daf6bc3f149d6a071dc9c68c27b472c3447a5c Mon Sep 17 00:00:00 2001 From: punit1111 Date: Fri, 25 Aug 2023 18:33:20 +0530 Subject: [PATCH 5/5] hide seek buttons for cupertino controls --- lib/src/cupertino/cupertino_controls.dart | 20 +------- lib/src/hit_area_controls.dart | 42 +++++++++-------- lib/src/seek_control_button.dart | 56 +++++++++++------------ 3 files changed, 49 insertions(+), 69 deletions(-) diff --git a/lib/src/cupertino/cupertino_controls.dart b/lib/src/cupertino/cupertino_controls.dart index b3624db84..39d770563 100644 --- a/lib/src/cupertino/cupertino_controls.dart +++ b/lib/src/cupertino/cupertino_controls.dart @@ -351,8 +351,6 @@ class _CupertinoControlsState extends State final bool isFinished = _latestValue.position >= _latestValue.duration; final bool showPlayButton = widget.showPlayButton && !_latestValue.isPlaying && !_dragging; - final bool showSeekButton = - widget.showSeekButton && !_latestValue.isPlaying && !_dragging; return HitAreaControls( onTapPlay: _latestValue.isPlaying @@ -369,10 +367,8 @@ class _CupertinoControlsState extends State isFinished: isFinished, isPlaying: controller.value.isPlaying, showPlayButton: showPlayButton, - showSeekButton: showSeekButton, + showSeekButton: false, onPressedPlay: _playPause, - seekRewind: _seekRewind, - seekForward: _seekForward, ); } @@ -811,20 +807,6 @@ class _CupertinoControlsState extends State _subtitlesPosition = controller.value.position; }); } - - void _seekTo({int seconds = 10}) { - setState(() { - controller.seekTo( - Duration( - seconds: _latestValue.position.inSeconds + seconds, - ), - ); - }); - } - - void _seekForward() => _seekTo(); - - void _seekRewind() => _seekTo(seconds: -10); } class _PlaybackSpeedDialog extends StatelessWidget { diff --git a/lib/src/hit_area_controls.dart b/lib/src/hit_area_controls.dart index b1e96c294..7e3deaf46 100644 --- a/lib/src/hit_area_controls.dart +++ b/lib/src/hit_area_controls.dart @@ -8,20 +8,20 @@ class HitAreaControls extends StatelessWidget { Key? key, required this.onTapPlay, required this.onPressedPlay, - required this.seekRewind, - required this.seekForward, required this.backgroundColor, required this.iconColor, required this.isFinished, required this.isPlaying, required this.showPlayButton, required this.showSeekButton, + this.seekRewind, + this.seekForward, }) : super(key: key); final VoidCallback onTapPlay; final VoidCallback onPressedPlay; - final VoidCallback seekRewind; - final VoidCallback seekForward; + final VoidCallback? seekRewind; + final VoidCallback? seekForward; final Color backgroundColor; final Color iconColor; final bool isFinished; @@ -34,14 +34,15 @@ class HitAreaControls extends StatelessWidget { return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - SeekControlButton( - backgroundColor: backgroundColor, - iconColor: iconColor, - show: showSeekButton, - onPressed: seekRewind, - onDoublePressed: seekRewind, - icon: Icons.fast_rewind, - ), + showSeekButton + ? SeekControlButton( + backgroundColor: backgroundColor, + iconColor: iconColor, + onPressed: seekRewind, + onDoublePressed: seekRewind, + icon: Icons.fast_rewind, + ) + : const SizedBox.shrink(), GestureDetector( onTap: onTapPlay, child: CenterPlayButton( @@ -53,14 +54,15 @@ class HitAreaControls extends StatelessWidget { onPressed: onPressedPlay, ), ), - SeekControlButton( - backgroundColor: backgroundColor, - iconColor: iconColor, - show: showSeekButton, - onPressed: seekForward, - onDoublePressed: seekForward, - icon: Icons.fast_forward, - ), + showSeekButton + ? SeekControlButton( + backgroundColor: backgroundColor, + iconColor: iconColor, + onPressed: seekForward, + onDoublePressed: seekForward, + icon: Icons.fast_forward, + ) + : const SizedBox.shrink(), ], ); } diff --git a/lib/src/seek_control_button.dart b/lib/src/seek_control_button.dart index 9cd5c1294..667cb6964 100644 --- a/lib/src/seek_control_button.dart +++ b/lib/src/seek_control_button.dart @@ -5,17 +5,15 @@ class SeekControlButton extends StatefulWidget { Key? key, required this.backgroundColor, required this.iconColor, - required this.show, required this.icon, - required this.onPressed, - required this.onDoublePressed, + this.onPressed, + this.onDoublePressed, }) : super(key: key); final Color backgroundColor; final Color iconColor; - final bool show; - final VoidCallback onPressed; - final VoidCallback onDoublePressed; + final VoidCallback? onPressed; + final VoidCallback? onDoublePressed; final IconData icon; @override @@ -30,31 +28,29 @@ class _SeekControlButtonState extends State { @override Widget build(BuildContext context) { - return widget.show - ? Expanded( - child: GestureDetector( - onDoubleTap: widget.onDoublePressed, - child: ColoredBox( - color: Colors.transparent, - child: Center( - child: DecoratedBox( - decoration: BoxDecoration( - color: widget.backgroundColor, - shape: BoxShape.circle, - ), - // Always set the iconSize on the IconButton, not on the Icon itself: - // https://github.com/flutter/flutter/issues/52980 - child: IconButton( - iconSize: 32, - padding: const EdgeInsets.all(12.0), - icon: Icon(widget.icon, color: widget.iconColor), - onPressed: widget.onPressed, - ), - ), - ), + return Expanded( + child: GestureDetector( + onDoubleTap: widget.onDoublePressed, + child: ColoredBox( + color: Colors.transparent, + child: Center( + child: DecoratedBox( + decoration: BoxDecoration( + color: widget.backgroundColor, + shape: BoxShape.circle, + ), + // Always set the iconSize on the IconButton, not on the Icon itself: + // https://github.com/flutter/flutter/issues/52980 + child: IconButton( + iconSize: 32, + padding: const EdgeInsets.all(12.0), + icon: Icon(widget.icon, color: widget.iconColor), + onPressed: widget.onPressed, ), ), - ) - : const SizedBox.shrink(); + ), + ), + ), + ); } }