fix(mobile): 简化火柴人位置计算逻辑
使用简单直接的比例计算: - 起点 = 昵称区域右边 (70px) - 终点 = 红旗左边 (containerWidth - 62px) - 火柴人位置 = 起点 + (终点 - 起点) * 进度 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
71304dbb69
commit
3e59d56f92
|
|
@ -183,7 +183,12 @@ class _StickmanRaceWidgetState extends State<StickmanRaceWidget>
|
||||||
|
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
height: raceTrackHeight,
|
height: raceTrackHeight,
|
||||||
child: Stack(
|
child: LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
final containerWidth = constraints.maxWidth;
|
||||||
|
|
||||||
|
return Stack(
|
||||||
|
clipBehavior: Clip.none,
|
||||||
children: [
|
children: [
|
||||||
// 背景赛道线
|
// 背景赛道线
|
||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
|
|
@ -212,59 +217,47 @@ class _StickmanRaceWidgetState extends State<StickmanRaceWidget>
|
||||||
...sortedRankings.asMap().entries.map((entry) {
|
...sortedRankings.asMap().entries.map((entry) {
|
||||||
final index = entry.key;
|
final index = entry.key;
|
||||||
final data = entry.value;
|
final data = entry.value;
|
||||||
return _buildStickman(data, index, sortedRankings.length, raceTrackHeight);
|
return _buildStickman(data, index, sortedRankings.length, raceTrackHeight, containerWidth);
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建单个火柴人
|
/// 构建单个火柴人
|
||||||
Widget _buildStickman(StickmanRankingData data, int rank, int total, double raceTrackHeight) {
|
Widget _buildStickman(StickmanRankingData data, int rank, int total, double raceTrackHeight, double containerWidth) {
|
||||||
// 计算水平位置 (根据进度)
|
// 进度 (0.0 - 1.0)
|
||||||
final horizontalProgress = data.progress;
|
final progress = data.progress;
|
||||||
|
|
||||||
// 计算垂直位置 (不同排名在不同跑道)
|
// 计算垂直位置 (不同排名在不同跑道)
|
||||||
// 预留顶部和底部空间
|
|
||||||
final usableHeight = raceTrackHeight - 40;
|
final usableHeight = raceTrackHeight - 40;
|
||||||
final trackHeight = usableHeight / total;
|
final trackHeight = usableHeight / total;
|
||||||
final verticalPosition = rank * trackHeight + 10;
|
final verticalPosition = rank * trackHeight + 10;
|
||||||
|
|
||||||
|
// 简单直接的计算:
|
||||||
|
// 起点:昵称区域右边 (70)
|
||||||
|
// 终点:红旗左边 (containerWidth - 8(红旗right) - 24(红旗宽) - 30(火柴人半宽))
|
||||||
|
// 火柴人中心位置 = 起点 + (终点 - 起点) * 进度
|
||||||
|
const double startX = 70.0;
|
||||||
|
final double endX = containerWidth - 62.0;
|
||||||
|
final double stickmanCenterX = startX + (endX - startX) * progress;
|
||||||
|
|
||||||
return AnimatedBuilder(
|
return AnimatedBuilder(
|
||||||
animation: _bounceController,
|
animation: _bounceController,
|
||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
// 添加上下弹跳效果
|
|
||||||
final bounce = _bounceController.value * 3;
|
final bounce = _bounceController.value * 3;
|
||||||
|
|
||||||
// 计算可用宽度,让火柴人在100%时正好到达红旗位置
|
return Stack(
|
||||||
final screenWidth = MediaQuery.of(context).size.width;
|
clipBehavior: Clip.none,
|
||||||
final containerWidth = screenWidth - 32 - 32; // 页面padding + 容器padding
|
|
||||||
final stickmanColumnWidth = 60.0; // 火柴人+数量标签列的宽度
|
|
||||||
final flagRightMargin = 8.0; // 红旗的right值
|
|
||||||
final flagWidth = 24.0; // 红旗图标宽度
|
|
||||||
final nicknameAreaWidth = 65.0; // 昵称区域宽度
|
|
||||||
final gap = 4.0; // 昵称和火柴人之间的最小间距
|
|
||||||
|
|
||||||
// 100%时火柴人列的右边缘应该对齐红旗左边缘
|
|
||||||
// 红旗左边位置 = containerWidth - flagRightMargin - flagWidth
|
|
||||||
// 火柴人列右边 = stickmanLeftPosition + stickmanColumnWidth
|
|
||||||
// 所以 100% 时: stickmanLeftPosition = containerWidth - flagRightMargin - flagWidth - stickmanColumnWidth
|
|
||||||
final endPosition = containerWidth - flagRightMargin - flagWidth - stickmanColumnWidth;
|
|
||||||
final startPosition = nicknameAreaWidth + gap;
|
|
||||||
final availableWidth = endPosition - startPosition;
|
|
||||||
final stickmanLeftPosition = startPosition + availableWidth * horizontalProgress;
|
|
||||||
|
|
||||||
return Positioned(
|
|
||||||
left: 0,
|
|
||||||
top: verticalPosition - bounce,
|
|
||||||
child: SizedBox(
|
|
||||||
width: containerWidth,
|
|
||||||
child: Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
// 昵称标签 - 固定在左边,与数量标签同一水平高度
|
// 昵称标签 - 固定在左边
|
||||||
SizedBox(
|
Positioned(
|
||||||
width: nicknameAreaWidth,
|
left: 0,
|
||||||
|
top: verticalPosition + 15 - bounce,
|
||||||
|
child: SizedBox(
|
||||||
|
width: 65,
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
|
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
|
|
@ -281,8 +274,7 @@ class _StickmanRaceWidgetState extends State<StickmanRaceWidget>
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 9,
|
fontSize: 9,
|
||||||
fontFamily: 'Inter',
|
fontFamily: 'Inter',
|
||||||
fontWeight:
|
fontWeight: data.isCurrentUser ? FontWeight.w600 : FontWeight.w400,
|
||||||
data.isCurrentUser ? FontWeight.w600 : FontWeight.w400,
|
|
||||||
color: data.isCurrentUser
|
color: data.isCurrentUser
|
||||||
? const Color(0xFFD4AF37)
|
? const Color(0xFFD4AF37)
|
||||||
: const Color(0xFF5D4037),
|
: const Color(0xFF5D4037),
|
||||||
|
|
@ -292,12 +284,12 @@ class _StickmanRaceWidgetState extends State<StickmanRaceWidget>
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// 间隔 + 火柴人位置
|
|
||||||
SizedBox(
|
|
||||||
width: stickmanLeftPosition - nicknameAreaWidth,
|
|
||||||
),
|
),
|
||||||
// 火柴人和数量标签
|
// 火柴人和数量标签
|
||||||
Column(
|
Positioned(
|
||||||
|
left: stickmanCenterX - 30, // 火柴人宽度60的一半
|
||||||
|
top: verticalPosition - bounce,
|
||||||
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
// 完成数量标签
|
// 完成数量标签
|
||||||
|
|
@ -333,9 +325,8 @@ class _StickmanRaceWidgetState extends State<StickmanRaceWidget>
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue