Skip to content

Commit 9395d54

Browse files
fix: pass latestDraggableOffset to _ProgressBarPainter
1 parent 015a986 commit 9395d54

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/src/progress_bar.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ class _VideoProgressBarState extends State<VideoProgressBar> {
5858
}
5959

6060
void _seekToRelativePosition(Offset globalPosition) {
61-
controller.seekTo(context.calcRelativePosition(
61+
final relativePosition = context.calcRelativePosition(
6262
controller.value.duration,
6363
globalPosition,
64-
));
64+
);
65+
controller.seekTo(relativePosition ?? Duration.zero);
6566
}
6667

6768
@override
@@ -74,6 +75,7 @@ class _VideoProgressBarState extends State<VideoProgressBar> {
7475
barHeight: widget.barHeight,
7576
handleHeight: widget.handleHeight,
7677
drawShadow: widget.drawShadow,
78+
latestDraggableOffset: _latestDraggableOffset,
7779
),
7880
);
7981

@@ -181,7 +183,7 @@ class _ProgressBarPainter extends CustomPainter {
181183
final double barHeight;
182184
final double handleHeight;
183185
final bool drawShadow;
184-
final Duration draggableValue;
186+
final Duration? draggableValue;
185187

186188
@override
187189
bool shouldRepaint(CustomPainter painter) {
@@ -205,8 +207,8 @@ class _ProgressBarPainter extends CustomPainter {
205207
if (!value.isInitialized) {
206208
return;
207209
}
208-
final double playedPartPercent = (draggableValue != Duration.zero
209-
? draggableValue.inMilliseconds
210+
final double playedPartPercent = (draggableValue != null
211+
? draggableValue!.inMilliseconds
210212
: value.position.inMilliseconds) /
211213
value.duration.inMilliseconds;
212214
final double playedPart =
@@ -257,11 +259,11 @@ class _ProgressBarPainter extends CustomPainter {
257259
}
258260

259261
extension RelativePositionExtensions on BuildContext {
260-
Duration calcRelativePosition(
262+
Duration? calcRelativePosition(
261263
Duration videoDuration,
262264
Offset? globalPosition,
263265
) {
264-
if (globalPosition == null) return Duration.zero;
266+
if (globalPosition == null) return null;
265267
final box = findRenderObject()! as RenderBox;
266268
final Offset tapPos = box.globalToLocal(globalPosition);
267269
final double relative = tapPos.dx / box.size.width;

0 commit comments

Comments
 (0)