Skip to content

Commit

Permalink
Merge pull request fluttercommunity#798 from glucoseinc/fix/progress-…
Browse files Browse the repository at this point in the history
…bar-does-not-follow-drag

Fix: Progress bar does not follow drag fluttercommunity#789
  • Loading branch information
diegotori authored Nov 27, 2023
2 parents 015a986 + fadcdc4 commit 2ac2ff8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
4 changes: 1 addition & 3 deletions lib/src/material/widgets/options_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ class _OptionsDialogState extends State<OptionsDialog> {
itemCount: widget.options.length,
itemBuilder: (context, i) {
return ListTile(
onTap: widget.options[i].onTap != null
? widget.options[i].onTap!
: null,
onTap: widget.options[i].onTap,
leading: Icon(widget.options[i].iconData),
title: Text(widget.options[i].title),
subtitle: widget.options[i].subtitle != null
Expand Down
25 changes: 15 additions & 10 deletions lib/src/progress_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class _VideoProgressBarState extends State<VideoProgressBar> {
barHeight: widget.barHeight,
handleHeight: widget.handleHeight,
drawShadow: widget.drawShadow,
latestDraggableOffset: _latestDraggableOffset,
),
);

Expand Down Expand Up @@ -151,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,
Expand All @@ -181,7 +184,10 @@ class _ProgressBarPainter extends CustomPainter {
final double barHeight;
final double handleHeight;
final bool drawShadow;
final Duration draggableValue;

/// The value of the draggable progress bar.
/// If null, the progress bar is not being dragged.
final Duration? draggableValue;

@override
bool shouldRepaint(CustomPainter painter) {
Expand All @@ -205,8 +211,8 @@ class _ProgressBarPainter extends CustomPainter {
if (!value.isInitialized) {
return;
}
final double playedPartPercent = (draggableValue != Duration.zero
? draggableValue.inMilliseconds
final double playedPartPercent = (draggableValue != null
? draggableValue!.inMilliseconds
: value.position.inMilliseconds) /
value.duration.inMilliseconds;
final double playedPart =
Expand Down Expand Up @@ -259,12 +265,11 @@ class _ProgressBarPainter extends CustomPainter {
extension RelativePositionExtensions on BuildContext {
Duration calcRelativePosition(
Duration videoDuration,
Offset? globalPosition,
Offset globalPosition,
) {
if (globalPosition == null) return Duration.zero;
final box = findRenderObject()! as RenderBox;
final Offset tapPos = box.globalToLocal(globalPosition);
final double relative = tapPos.dx / box.size.width;
final double relative = (tapPos.dx / box.size.width).clamp(0, 1);
final Duration position = videoDuration * relative;
return position;
}
Expand Down

0 comments on commit 2ac2ff8

Please sign in to comment.