fix(player): 延长飘心并显示毫秒计时
This commit is contained in:
1 parent
84b24775d6
commit
810ca5bf9d
4 files changed
+165
-40
No files matched your search
@@ -1,13 +1,14 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
|
||||
const int _heartDurationMs = 680;
|
||||
const int _heartDurationMs = 1500;
|
||||
const double _heartPopPortion = 0.18;
|
||||
const double _heartStartScale = 0.7;
|
||||
const double _heartHoldPortion = 0.45;
|
||||
const double _heartHoldPortion = 0.55;
|
||||
|
||||
const List<_HeartParticle> _hearts = [
|
||||
_HeartParticle(
|
||||
@@ -35,9 +36,14 @@ const List<_HeartParticle> _hearts = [
|
||||
|
||||
/// 双击点赞时,在点击位置飘出一小簇心。
|
||||
class PlayerDoubleTapHeartBurst extends StatefulWidget {
|
||||
const PlayerDoubleTapHeartBurst({super.key, required this.onCompleted});
|
||||
const PlayerDoubleTapHeartBurst({
|
||||
super.key,
|
||||
required this.onCompleted,
|
||||
this.origin = Offset.zero,
|
||||
});
|
||||
|
||||
final VoidCallback onCompleted;
|
||||
final Offset origin;
|
||||
|
||||
@override
|
||||
State<PlayerDoubleTapHeartBurst> createState() =>
|
||||
@@ -47,14 +53,24 @@ class PlayerDoubleTapHeartBurst extends StatefulWidget {
|
||||
class _PlayerDoubleTapHeartBurstState extends State<PlayerDoubleTapHeartBurst>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _controller;
|
||||
final Stopwatch _lifetime = Stopwatch();
|
||||
bool _completed = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_lifetime.start();
|
||||
final total = _hearts
|
||||
.map((heart) => heart.delay + _heartDurationMs)
|
||||
.reduce((left, right) => left > right ? left : right);
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'[player] phase=heart-burst-start '
|
||||
'id=${identityHashCode(this)} count=${_hearts.length} '
|
||||
'configuredMs=$total at=${widget.origin.dx.toStringAsFixed(1)},'
|
||||
'${widget.origin.dy.toStringAsFixed(1)}',
|
||||
);
|
||||
}
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: Duration(milliseconds: total),
|
||||
@@ -65,11 +81,37 @@ class _PlayerDoubleTapHeartBurstState extends State<PlayerDoubleTapHeartBurst>
|
||||
void _onStatus(AnimationStatus status) {
|
||||
if (status != AnimationStatus.completed || _completed) return;
|
||||
_completed = true;
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'[player] phase=heart-burst-complete '
|
||||
'id=${identityHashCode(this)} '
|
||||
'configuredMs=${_controller.duration?.inMilliseconds ?? 0}',
|
||||
);
|
||||
}
|
||||
widget.onCompleted();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (kDebugMode) {
|
||||
final elapsedMs = _completed
|
||||
? _controller.duration?.inMilliseconds ?? 0
|
||||
: _lifetime.elapsedMilliseconds;
|
||||
debugPrint(
|
||||
'[player] phase=heart-burst-dispose '
|
||||
'id=${identityHashCode(this)} elapsedMs=$elapsedMs '
|
||||
'completed=${_completed ? 1 : 0}',
|
||||
);
|
||||
if (!_completed) {
|
||||
debugPrintStack(
|
||||
maxFrames: 30,
|
||||
label:
|
||||
'[player] heart-burst-premature-dispose '
|
||||
'id=${identityHashCode(this)} mount=tap-gesture-region',
|
||||
);
|
||||
}
|
||||
}
|
||||
_lifetime.stop();
|
||||
_controller
|
||||
..removeStatusListener(_onStatus)
|
||||
..dispose();
|
||||
@@ -86,10 +128,26 @@ class _PlayerDoubleTapHeartBurstState extends State<PlayerDoubleTapHeartBurst>
|
||||
final elapsed =
|
||||
_controller.value * _controller.duration!.inMilliseconds;
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
for (var index = 0; index < _hearts.length; index++)
|
||||
_heart(_hearts[index], elapsed, index),
|
||||
if (kDebugMode)
|
||||
Positioned(
|
||||
left: widget.origin.dx + 8,
|
||||
top: widget.origin.dy,
|
||||
child: IgnorePointer(
|
||||
child: Text(
|
||||
'${elapsed.round()}ms',
|
||||
key: const Key('heart-burst-elapsed-debug'),
|
||||
style: const TextStyle(
|
||||
color: Colors.white60,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
@@ -113,8 +171,8 @@ class _PlayerDoubleTapHeartBurstState extends State<PlayerDoubleTapHeartBurst>
|
||||
? 1.0
|
||||
: 1 - ((progress - _heartHoldPortion) / (1 - _heartHoldPortion));
|
||||
return Positioned(
|
||||
left: heart.drift * move - heart.size / 2,
|
||||
top: -heart.size / 2 - heart.travel * move,
|
||||
left: widget.origin.dx + heart.drift * move - heart.size / 2,
|
||||
top: widget.origin.dy - heart.size / 2 - heart.travel * move,
|
||||
child: Opacity(
|
||||
opacity: opacity.clamp(0.0, 1.0),
|
||||
child: Transform.scale(
|
||||
|
||||
Reference in new issue
Block a user