@@ -74,6 +74,7 @@ class _VideoProgressBarState extends State<VideoProgressBar> {
74
74
barHeight: widget.barHeight,
75
75
handleHeight: widget.handleHeight,
76
76
drawShadow: widget.drawShadow,
77
+ latestDraggableOffset: _latestDraggableOffset,
77
78
),
78
79
);
79
80
@@ -151,10 +152,12 @@ class StaticProgressBar extends StatelessWidget {
151
152
child: CustomPaint (
152
153
painter: _ProgressBarPainter (
153
154
value: value,
154
- draggableValue: context.calcRelativePosition (
155
- value.duration,
156
- latestDraggableOffset,
157
- ),
155
+ draggableValue: latestDraggableOffset != null
156
+ ? context.calcRelativePosition (
157
+ value.duration,
158
+ latestDraggableOffset! ,
159
+ )
160
+ : null ,
158
161
colors: colors,
159
162
barHeight: barHeight,
160
163
handleHeight: handleHeight,
@@ -181,7 +184,10 @@ class _ProgressBarPainter extends CustomPainter {
181
184
final double barHeight;
182
185
final double handleHeight;
183
186
final bool drawShadow;
184
- final Duration draggableValue;
187
+
188
+ /// The value of the draggable progress bar.
189
+ /// If null, the progress bar is not being dragged.
190
+ final Duration ? draggableValue;
185
191
186
192
@override
187
193
bool shouldRepaint (CustomPainter painter) {
@@ -205,8 +211,8 @@ class _ProgressBarPainter extends CustomPainter {
205
211
if (! value.isInitialized) {
206
212
return ;
207
213
}
208
- final double playedPartPercent = (draggableValue != Duration .zero
209
- ? draggableValue.inMilliseconds
214
+ final double playedPartPercent = (draggableValue != null
215
+ ? draggableValue! .inMilliseconds
210
216
: value.position.inMilliseconds) /
211
217
value.duration.inMilliseconds;
212
218
final double playedPart =
@@ -259,12 +265,11 @@ class _ProgressBarPainter extends CustomPainter {
259
265
extension RelativePositionExtensions on BuildContext {
260
266
Duration calcRelativePosition (
261
267
Duration videoDuration,
262
- Offset ? globalPosition,
268
+ Offset globalPosition,
263
269
) {
264
- if (globalPosition == null ) return Duration .zero;
265
270
final box = findRenderObject ()! as RenderBox ;
266
271
final Offset tapPos = box.globalToLocal (globalPosition);
267
- final double relative = tapPos.dx / box.size.width;
272
+ final double relative = ( tapPos.dx / box.size.width). clamp ( 0 , 1 ) ;
268
273
final Duration position = videoDuration * relative;
269
274
return position;
270
275
}
0 commit comments