From 9395d549778982bfc730331da232e923d2ad75a1 Mon Sep 17 00:00:00 2001 From: koutaro-masaki Date: Mon, 27 Nov 2023 21:07:42 +0900 Subject: [PATCH 1/4] fix: pass latestDraggableOffset to _ProgressBarPainter --- lib/src/progress_bar.dart | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/src/progress_bar.dart b/lib/src/progress_bar.dart index 067078688..35b6b5eb8 100644 --- a/lib/src/progress_bar.dart +++ b/lib/src/progress_bar.dart @@ -58,10 +58,11 @@ class _VideoProgressBarState extends State { } void _seekToRelativePosition(Offset globalPosition) { - controller.seekTo(context.calcRelativePosition( + final relativePosition = context.calcRelativePosition( controller.value.duration, globalPosition, - )); + ); + controller.seekTo(relativePosition ?? Duration.zero); } @override @@ -74,6 +75,7 @@ class _VideoProgressBarState extends State { barHeight: widget.barHeight, handleHeight: widget.handleHeight, drawShadow: widget.drawShadow, + latestDraggableOffset: _latestDraggableOffset, ), ); @@ -181,7 +183,7 @@ class _ProgressBarPainter extends CustomPainter { final double barHeight; final double handleHeight; final bool drawShadow; - final Duration draggableValue; + final Duration? draggableValue; @override bool shouldRepaint(CustomPainter painter) { @@ -205,8 +207,8 @@ class _ProgressBarPainter extends CustomPainter { if (!value.isInitialized) { return; } - final double playedPartPercent = (draggableValue != Duration.zero - ? draggableValue.inMilliseconds + final double playedPartPercent = (draggableValue != null + ? draggableValue!.inMilliseconds : value.position.inMilliseconds) / value.duration.inMilliseconds; final double playedPart = @@ -257,11 +259,11 @@ class _ProgressBarPainter extends CustomPainter { } extension RelativePositionExtensions on BuildContext { - Duration calcRelativePosition( + Duration? calcRelativePosition( Duration videoDuration, Offset? globalPosition, ) { - if (globalPosition == null) return Duration.zero; + if (globalPosition == null) return null; final box = findRenderObject()! as RenderBox; final Offset tapPos = box.globalToLocal(globalPosition); final double relative = tapPos.dx / box.size.width; From bf813b6ea5a8c8661450768a4148d6086ef648ff Mon Sep 17 00:00:00 2001 From: koutaro-masaki Date: Mon, 27 Nov 2023 21:11:23 +0900 Subject: [PATCH 2/4] fix: Restrict pointer to progress bar bounds --- lib/src/progress_bar.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/progress_bar.dart b/lib/src/progress_bar.dart index 35b6b5eb8..448ba2be8 100644 --- a/lib/src/progress_bar.dart +++ b/lib/src/progress_bar.dart @@ -266,7 +266,7 @@ extension RelativePositionExtensions on BuildContext { if (globalPosition == null) return null; final box = findRenderObject()! as RenderBox; final Offset tapPos = box.globalToLocal(globalPosition); - final double relative = tapPos.dx / box.size.width; + final double relative = (tapPos.dx / box.size.width).clamp(0, 1); final Duration position = videoDuration * relative; return position; } From d1a99e1967544eca691c67de83038a4e92ad85dd Mon Sep 17 00:00:00 2001 From: koutaro-masaki Date: Mon, 27 Nov 2023 22:06:57 +0900 Subject: [PATCH 3/4] fix: lint issue --- lib/src/material/widgets/options_dialog.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/src/material/widgets/options_dialog.dart b/lib/src/material/widgets/options_dialog.dart index 450a3b9ca..bca7a9a2d 100644 --- a/lib/src/material/widgets/options_dialog.dart +++ b/lib/src/material/widgets/options_dialog.dart @@ -28,9 +28,7 @@ class _OptionsDialogState extends State { itemCount: widget.options.length, itemBuilder: (context, i) { return ListTile( - onTap: widget.options[i].onTap != null - ? widget.options[i].onTap! - : null, + onTap: widget.options[i].onTap, leading: Icon(widget.options[i].iconData), title: Text(widget.options[i].title), subtitle: widget.options[i].subtitle != null From fadcdc4ed64db257cb185f46d2ca6b307d9bd379 Mon Sep 17 00:00:00 2001 From: koutaro-masaki Date: Mon, 27 Nov 2023 22:52:12 +0900 Subject: [PATCH 4/4] refactor: Remove unnecessary nullability --- lib/src/progress_bar.dart | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/src/progress_bar.dart b/lib/src/progress_bar.dart index 448ba2be8..80cd23375 100644 --- a/lib/src/progress_bar.dart +++ b/lib/src/progress_bar.dart @@ -58,11 +58,10 @@ class _VideoProgressBarState extends State { } void _seekToRelativePosition(Offset globalPosition) { - final relativePosition = context.calcRelativePosition( + controller.seekTo(context.calcRelativePosition( controller.value.duration, globalPosition, - ); - controller.seekTo(relativePosition ?? Duration.zero); + )); } @override @@ -153,10 +152,12 @@ class StaticProgressBar extends StatelessWidget { child: CustomPaint( painter: _ProgressBarPainter( value: value, - draggableValue: context.calcRelativePosition( - value.duration, - latestDraggableOffset, - ), + draggableValue: latestDraggableOffset != null + ? context.calcRelativePosition( + value.duration, + latestDraggableOffset!, + ) + : null, colors: colors, barHeight: barHeight, handleHeight: handleHeight, @@ -183,6 +184,9 @@ class _ProgressBarPainter extends CustomPainter { final double barHeight; final double handleHeight; final bool drawShadow; + + /// The value of the draggable progress bar. + /// If null, the progress bar is not being dragged. final Duration? draggableValue; @override @@ -259,11 +263,10 @@ class _ProgressBarPainter extends CustomPainter { } extension RelativePositionExtensions on BuildContext { - Duration? calcRelativePosition( + Duration calcRelativePosition( Duration videoDuration, - Offset? globalPosition, + Offset globalPosition, ) { - if (globalPosition == null) return null; final box = findRenderObject()! as RenderBox; final Offset tapPos = box.globalToLocal(globalPosition); final double relative = (tapPos.dx / box.size.width).clamp(0, 1);