Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Progress bar does not follow drag #789 #798

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading