fix: remove redundant thumbnail popup during dpad timeline seeking
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -61,43 +60,12 @@ class TimelineSlider extends StatefulWidget {
|
||||
class _TimelineSliderState extends State<TimelineSlider> {
|
||||
double? _mousePosition;
|
||||
double? _dragValue;
|
||||
bool _showKeySeekThumbnail = false;
|
||||
Timer? _keySeekTimer;
|
||||
|
||||
// Must match the slider track inset: max(overlayRadius, thumbRadius)
|
||||
static const _sliderPadding = 12.0;
|
||||
|
||||
static const _thumbWidth = 160.0;
|
||||
static const _thumbHeight = 90.0;
|
||||
static const _keySeekThumbnailTimeout = Duration(milliseconds: 800);
|
||||
|
||||
@override
|
||||
void didUpdateWidget(TimelineSlider oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
// Detect user-initiated seeks. A normal playback will advance the timeline
|
||||
// a very short amount. But a bigger jump indicates that the user changed position.
|
||||
// For now we will check half a second, but this can probably be made higher.
|
||||
if (widget.thumbnailDataBuilder != null && _dragValue == null) {
|
||||
final delta = (widget.position.inMilliseconds - oldWidget.position.inMilliseconds).abs();
|
||||
if (delta > 500 && widget.focusNode?.hasFocus == true) {
|
||||
_showKeySeekThumbnail = true;
|
||||
_resetKeySeekTimer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_keySeekTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _resetKeySeekTimer() {
|
||||
_keySeekTimer?.cancel();
|
||||
_keySeekTimer = Timer(_keySeekThumbnailTimeout, () {
|
||||
if (mounted) setState(() => _showKeySeekThumbnail = false);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildTooltip(double sliderWidth, double pixelX, Duration time) {
|
||||
final thumbnailData = widget.thumbnailDataBuilder?.call(time);
|
||||
@@ -183,12 +151,6 @@ class _TimelineSliderState extends State<TimelineSlider> {
|
||||
final fraction = ((_mousePosition! - _sliderPadding) / trackWidth).clamp(0.0, 1.0);
|
||||
final time = Duration(milliseconds: (fraction * durationMs).round());
|
||||
tooltip = _buildTooltip(sliderWidth, _mousePosition!, time);
|
||||
} else if (_showKeySeekThumbnail && widget.thumbnailDataBuilder != null) {
|
||||
// Show tooltip at current playback position when user is actively seeking via d-pad/keyboard
|
||||
// Note that this has the lowest priority, so if the user hovers, that will show instead
|
||||
final fraction = (widget.position.inMilliseconds / durationMs).clamp(0.0, 1.0);
|
||||
final px = _sliderPadding + fraction * trackWidth;
|
||||
tooltip = _buildTooltip(sliderWidth, px, widget.position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user