Skip to content

Commit fadcdc4

Browse files
refactor: Remove unnecessary nullability
1 parent d1a99e1 commit fadcdc4

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

lib/src/progress_bar.dart

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@ class _VideoProgressBarState extends State<VideoProgressBar> {
5858
}
5959

6060
void _seekToRelativePosition(Offset globalPosition) {
61-
final relativePosition = context.calcRelativePosition(
61+
controller.seekTo(context.calcRelativePosition(
6262
controller.value.duration,
6363
globalPosition,
64-
);
65-
controller.seekTo(relativePosition ?? Duration.zero);
64+
));
6665
}
6766

6867
@override
@@ -153,10 +152,12 @@ class StaticProgressBar extends StatelessWidget {
153152
child: CustomPaint(
154153
painter: _ProgressBarPainter(
155154
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,
160161
colors: colors,
161162
barHeight: barHeight,
162163
handleHeight: handleHeight,
@@ -183,6 +184,9 @@ class _ProgressBarPainter extends CustomPainter {
183184
final double barHeight;
184185
final double handleHeight;
185186
final bool drawShadow;
187+
188+
/// The value of the draggable progress bar.
189+
/// If null, the progress bar is not being dragged.
186190
final Duration? draggableValue;
187191

188192
@override
@@ -259,11 +263,10 @@ class _ProgressBarPainter extends CustomPainter {
259263
}
260264

261265
extension RelativePositionExtensions on BuildContext {
262-
Duration? calcRelativePosition(
266+
Duration calcRelativePosition(
263267
Duration videoDuration,
264-
Offset? globalPosition,
268+
Offset globalPosition,
265269
) {
266-
if (globalPosition == null) return null;
267270
final box = findRenderObject()! as RenderBox;
268271
final Offset tapPos = box.globalToLocal(globalPosition);
269272
final double relative = (tapPos.dx / box.size.width).clamp(0, 1);

0 commit comments

Comments
 (0)