Fix Slider assertion error when skipping past video duration

Prevent an AssertionError in the Slider widget when the skip duration
button causes the value to exceed the video's maximum duration.
Clamp the Slider's value to the range [0, max]
using `clamp(0.0, maxValue).toDouble()` to ensure it stays within bounds.

Exception example:
```
Exception has occurred.
_AssertionError ('package:flutter/src/material/slider.dart': Failed assertion: line 199 pos 10: 'value >= min && value <= max': Value 1410000.0 is not between minimum 0.0 and maximum 1409533.0)
```
This commit is contained in:
NBA2K1 2025-05-17 21:44:12 +02:00
parent 3bb8c1acdf
commit 1e0951be42

View file

@ -61,6 +61,10 @@ class CustomSeekBarState extends State<CustomSeekBar> {
final isDesktop = Platform.isMacOS || Platform.isWindows || Platform.isLinux;
@override
Widget build(BuildContext context) {
final maxValue = max(duration.inMilliseconds.toDouble(), 0).toDouble();
final rawValue =
(widget.delta ?? tempPosition ?? position).inMilliseconds.toDouble();
final clampedValue = rawValue.clamp(0, maxValue).toDouble();
return SizedBox(
height: 20,
child: Row(
@ -88,12 +92,8 @@ class CustomSeekBarState extends State<CustomSeekBar> {
overlayShape: const RoundSliderOverlayShape(overlayRadius: 5.0),
),
child: Slider(
max: max(duration.inMilliseconds.toDouble(), 0),
value: max(
(widget.delta ?? tempPosition ?? position).inMilliseconds
.toDouble(),
0,
),
max: maxValue,
value: clampedValue,
secondaryTrackValue: max(buffer.inMilliseconds.toDouble(), 0),
onChanged: (value) {
widget.onSeekStart?.call(