@@ -58,11 +58,10 @@ class _VideoProgressBarState extends State<VideoProgressBar> {
58
58
}
59
59
60
60
void _seekToRelativePosition (Offset globalPosition) {
61
- final relativePosition = context.calcRelativePosition (
61
+ controller. seekTo ( context.calcRelativePosition (
62
62
controller.value.duration,
63
63
globalPosition,
64
- );
65
- controller.seekTo (relativePosition ?? Duration .zero);
64
+ ));
66
65
}
67
66
68
67
@override
@@ -153,10 +152,12 @@ class StaticProgressBar extends StatelessWidget {
153
152
child: CustomPaint (
154
153
painter: _ProgressBarPainter (
155
154
value: value,
156
- draggableValue: context.calcRelativePosition (
157
- value.duration,
158
- latestDraggableOffset,
159
- ),
155
+ draggableValue: latestDraggableOffset != null
156
+ ? context.calcRelativePosition (
157
+ value.duration,
158
+ latestDraggableOffset! ,
159
+ )
160
+ : null ,
160
161
colors: colors,
161
162
barHeight: barHeight,
162
163
handleHeight: handleHeight,
@@ -183,6 +184,9 @@ class _ProgressBarPainter extends CustomPainter {
183
184
final double barHeight;
184
185
final double handleHeight;
185
186
final bool drawShadow;
187
+
188
+ /// The value of the draggable progress bar.
189
+ /// If null, the progress bar is not being dragged.
186
190
final Duration ? draggableValue;
187
191
188
192
@override
@@ -259,11 +263,10 @@ class _ProgressBarPainter extends CustomPainter {
259
263
}
260
264
261
265
extension RelativePositionExtensions on BuildContext {
262
- Duration ? calcRelativePosition (
266
+ Duration calcRelativePosition (
263
267
Duration videoDuration,
264
- Offset ? globalPosition,
268
+ Offset globalPosition,
265
269
) {
266
- if (globalPosition == null ) return null ;
267
270
final box = findRenderObject ()! as RenderBox ;
268
271
final Offset tapPos = box.globalToLocal (globalPosition);
269
272
final double relative = (tapPos.dx / box.size.width).clamp (0 , 1 );
0 commit comments