From fadcdc4ed64db257cb185f46d2ca6b307d9bd379 Mon Sep 17 00:00:00 2001 From: koutaro-masaki Date: Mon, 27 Nov 2023 22:52:12 +0900 Subject: [PATCH] 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);