fix(player): 延长飘心并显示毫秒计时

This commit is contained in:
Zhou Weidong committed 2026-10-26 18:48:12 +08:00
1 parent 84b24775d6
commit 810ca5bf9d
4 files changed
+165 -40

No files matched your search

@@ -2,6 +2,7 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'player_double_tap_hearts.dart';
@@ -47,12 +48,18 @@ class _PlayerTapGestureRegionState extends State<PlayerTapGestureRegion> {
int _downSerial = 0;
int _tapSeq = 0;
int _nextHeartBurstId = 0;
final List<({int id, Offset position})> _heartBursts = [];
final Map<int, OverlayEntry> _heartOverlayEntries = {};
@override
void dispose() {
_tapSeq++;
_singleTapTimer?.cancel();
for (final entry in _heartOverlayEntries.values.toList()) {
entry
..remove()
..dispose();
}
_heartOverlayEntries.clear();
super.dispose();
}
@@ -78,25 +85,6 @@ class _PlayerTapGestureRegionState extends State<PlayerTapGestureRegion> {
onLongPressEnd: (_) => widget.onInteractionEnd(),
onLongPressCancel: widget.onInteractionEnd,
),
if (_heartBursts.isNotEmpty)
Positioned.fill(
child: IgnorePointer(
child: Stack(
clipBehavior: Clip.none,
children: [
for (final burst in _heartBursts)
Positioned(
left: burst.position.dx,
top: burst.position.dy - 10,
child: PlayerDoubleTapHeartBurst(
key: ValueKey(burst.id),
onCompleted: () => _removeHeartBurst(burst.id),
),
),
],
),
),
),
],
),
),
@@ -138,7 +126,7 @@ class _PlayerTapGestureRegionState extends State<PlayerTapGestureRegion> {
void _handleTapUp(TapUpDetails details) {
final now = _now();
if (_doubleTapDown || _singleTapBlocked(now)) {
_handleDoubleTapLike(details.localPosition);
_handleDoubleTapLike(details.globalPosition);
return;
}
final serial = _downSerial;
@@ -156,19 +144,48 @@ class _PlayerTapGestureRegionState extends State<PlayerTapGestureRegion> {
_singleTapTimer = pending;
}
void _handleDoubleTapLike(Offset position) {
void _handleDoubleTapLike(Offset globalPosition) {
_blockSingleTapUntil = _now().add(_singleTapDelay);
_cancelPendingSingleTap();
if (!widget.doubleTapEnabled || _likedThisPair) return;
_likedThisPair = true;
final id = _nextHeartBurstId++;
setState(() => _heartBursts.add((id: id, position: position)));
widget.onDoubleTapLike?.call(position);
_showHeartBurst(globalPosition);
widget.onDoubleTapLike?.call(globalPosition);
}
void _removeHeartBurst(int id) {
if (!mounted) return;
setState(() => _heartBursts.removeWhere((burst) => burst.id == id));
void _showHeartBurst(Offset globalPosition) {
final overlay = Overlay.maybeOf(context, rootOverlay: true);
if (overlay == null) return;
final overlayBox = overlay.context.findRenderObject();
final origin = overlayBox is RenderBox
? overlayBox.globalToLocal(globalPosition)
: globalPosition;
final id = _nextHeartBurstId++;
late final OverlayEntry entry;
entry = OverlayEntry(
builder: (context) => Positioned.fill(
child: IgnorePointer(
child: PlayerDoubleTapHeartBurst(
key: ValueKey('heart-overlay-$id'),
origin: origin,
onCompleted: () => _removeHeartOverlay(id),
),
),
),
);
_heartOverlayEntries[id] = entry;
overlay.insert(entry);
}
void _removeHeartOverlay(int id) {
final entry = _heartOverlayEntries.remove(id);
if (entry == null) return;
entry
..remove()
..dispose();
if (kDebugMode) {
debugPrint('[player] phase=heart-burst-entry-removed id=$id');
}
}
void _handleLongPressStart(LongPressStartDetails details, double width) {