Skip to content

Commit 819118f

Browse files
lightbox: Apply correct fix for slider flickering
This changes makes it so that the async function `seekTo` is awaited before the `setState` in `Slider.onChangeEnd`, thus first invoking the `ValueNotifier.value` setter which as a side-effect calls the `setState` in `_handleVideoControllerUpdate`, and then the `setState` in `Slider.onChangeEnd`. Resulting in both setState calls to be coalesced in a single redraw. Whereas previously the unawaited `seekTo` call would delay the `ValueNotifier.value` setter call in a microtask.
1 parent 37ad773 commit 819118f

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

lib/widgets/lightbox.dart

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -277,20 +277,7 @@ class _VideoPositionSliderControlState extends State<_VideoPositionSliderControl
277277
}
278278

279279
void _handleVideoControllerUpdate() {
280-
setState(() {
281-
// After 'controller.seekTo' is called in 'Slider.onChangeEnd' the
282-
// position indicator switches back to the actual controller's position
283-
// but since the call 'seekTo' completes before the actual controller
284-
// updates are notified, the position indicator that switches to controller's
285-
// position can show the older position before the call to 'seekTo' for a
286-
// single frame, resulting in a glichty UX.
287-
//
288-
// To avoid that, we delay the position indicator switch from '_sliderValue' to
289-
// happen when we are notified of the controller update.
290-
if (_isSliderDragging && _sliderValue == widget.controller.value.position) {
291-
_isSliderDragging = false;
292-
}
293-
});
280+
setState(() {});
294281
}
295282

296283
static String _formatDuration(Duration value) {
@@ -325,15 +312,15 @@ class _VideoPositionSliderControlState extends State<_VideoPositionSliderControl
325312
_sliderValue = Duration(milliseconds: value.toInt());
326313
});
327314
},
328-
onChangeEnd: (value) {
315+
onChangeEnd: (value) async {
329316
final durationValue = Duration(milliseconds: value.toInt());
330-
setState(() {
331-
_sliderValue = durationValue;
332-
});
333-
widget.controller.seekTo(durationValue);
334-
335-
// The toggling back of '_isSliderDragging' is omitted here intentionally,
336-
// see '_handleVideoControllerUpdates'.
317+
await widget.controller.seekTo(durationValue);
318+
if (mounted) {
319+
setState(() {
320+
_sliderValue = durationValue;
321+
_isSliderDragging = false;
322+
});
323+
}
337324
},
338325
),
339326
),

0 commit comments

Comments
 (0)