Skip to content

Commit 2ac2ff8

Browse files
authored
Merge pull request #798 from glucoseinc/fix/progress-bar-does-not-follow-drag
Fix: Progress bar does not follow drag #789
2 parents 015a986 + fadcdc4 commit 2ac2ff8

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

lib/src/material/widgets/options_dialog.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ class _OptionsDialogState extends State<OptionsDialog> {
2828
itemCount: widget.options.length,
2929
itemBuilder: (context, i) {
3030
return ListTile(
31-
onTap: widget.options[i].onTap != null
32-
? widget.options[i].onTap!
33-
: null,
31+
onTap: widget.options[i].onTap,
3432
leading: Icon(widget.options[i].iconData),
3533
title: Text(widget.options[i].title),
3634
subtitle: widget.options[i].subtitle != null

lib/src/progress_bar.dart

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class _VideoProgressBarState extends State<VideoProgressBar> {
7474
barHeight: widget.barHeight,
7575
handleHeight: widget.handleHeight,
7676
drawShadow: widget.drawShadow,
77+
latestDraggableOffset: _latestDraggableOffset,
7778
),
7879
);
7980

@@ -151,10 +152,12 @@ class StaticProgressBar extends StatelessWidget {
151152
child: CustomPaint(
152153
painter: _ProgressBarPainter(
153154
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,
158161
colors: colors,
159162
barHeight: barHeight,
160163
handleHeight: handleHeight,
@@ -181,7 +184,10 @@ class _ProgressBarPainter extends CustomPainter {
181184
final double barHeight;
182185
final double handleHeight;
183186
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;
185191

186192
@override
187193
bool shouldRepaint(CustomPainter painter) {
@@ -205,8 +211,8 @@ class _ProgressBarPainter extends CustomPainter {
205211
if (!value.isInitialized) {
206212
return;
207213
}
208-
final double playedPartPercent = (draggableValue != Duration.zero
209-
? draggableValue.inMilliseconds
214+
final double playedPartPercent = (draggableValue != null
215+
? draggableValue!.inMilliseconds
210216
: value.position.inMilliseconds) /
211217
value.duration.inMilliseconds;
212218
final double playedPart =
@@ -259,12 +265,11 @@ class _ProgressBarPainter extends CustomPainter {
259265
extension RelativePositionExtensions on BuildContext {
260266
Duration calcRelativePosition(
261267
Duration videoDuration,
262-
Offset? globalPosition,
268+
Offset globalPosition,
263269
) {
264-
if (globalPosition == null) return Duration.zero;
265270
final box = findRenderObject()! as RenderBox;
266271
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);
268273
final Duration position = videoDuration * relative;
269274
return position;
270275
}

0 commit comments

Comments
 (0)