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:
hailin 2025-12-24 01:48:08 -08:00
parent 71304dbb69
commit 3e59d56f92
1 changed files with 118 additions and 127 deletions

View File

@ -183,159 +183,150 @@ class _StickmanRaceWidgetState extends State<StickmanRaceWidget>
return SizedBox(
height: raceTrackHeight,
child: Stack(
children: [
// 线
Positioned.fill(
child: CustomPaint(
painter: _TrackPainter(
trackCount: sortedRankings.length,
),
),
),
child: LayoutBuilder(
builder: (context, constraints) {
final containerWidth = constraints.maxWidth;
//
...List.generate(trackCount, (index) {
final verticalPosition = index * trackHeight + 10 + trackHeight / 2 - 16;
return Positioned(
right: 8,
top: verticalPosition,
child: const Icon(
Icons.flag,
color: Colors.red,
size: 24,
return Stack(
clipBehavior: Clip.none,
children: [
// 线
Positioned.fill(
child: CustomPaint(
painter: _TrackPainter(
trackCount: sortedRankings.length,
),
),
),
);
}),
//
...sortedRankings.asMap().entries.map((entry) {
final index = entry.key;
final data = entry.value;
return _buildStickman(data, index, sortedRankings.length, raceTrackHeight);
}),
],
//
...List.generate(trackCount, (index) {
final verticalPosition = index * trackHeight + 10 + trackHeight / 2 - 16;
return Positioned(
right: 8,
top: verticalPosition,
child: const Icon(
Icons.flag,
color: Colors.red,
size: 24,
),
);
}),
//
...sortedRankings.asMap().entries.map((entry) {
final index = entry.key;
final data = entry.value;
return _buildStickman(data, index, sortedRankings.length, raceTrackHeight, containerWidth);
}),
],
);
},
),
);
}
///
Widget _buildStickman(StickmanRankingData data, int rank, int total, double raceTrackHeight) {
// ()
final horizontalProgress = data.progress;
Widget _buildStickman(StickmanRankingData data, int rank, int total, double raceTrackHeight, double containerWidth) {
// (0.0 - 1.0)
final progress = data.progress;
// ()
//
final usableHeight = raceTrackHeight - 40;
final trackHeight = usableHeight / total;
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(
animation: _bounceController,
builder: (context, child) {
//
final bounce = _bounceController.value * 3;
// 100%
final screenWidth = MediaQuery.of(context).size.width;
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: [
// -
SizedBox(
width: nicknameAreaWidth,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
decoration: BoxDecoration(
color: data.isCurrentUser
? const Color(0xFFD4AF37).withValues(alpha: 0.2)
: Colors.white.withValues(alpha: 0.8),
borderRadius: BorderRadius.circular(8),
border: data.isCurrentUser
? Border.all(color: const Color(0xFFD4AF37), width: 1)
: null,
),
child: Text(
data.nickname,
style: TextStyle(
fontSize: 9,
fontFamily: 'Inter',
fontWeight:
data.isCurrentUser ? FontWeight.w600 : FontWeight.w400,
color: data.isCurrentUser
? const Color(0xFFD4AF37)
: const Color(0xFF5D4037),
),
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
return Stack(
clipBehavior: Clip.none,
children: [
// -
Positioned(
left: 0,
top: verticalPosition + 15 - bounce,
child: SizedBox(
width: 65,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
decoration: BoxDecoration(
color: data.isCurrentUser
? const Color(0xFFD4AF37).withValues(alpha: 0.2)
: Colors.white.withValues(alpha: 0.8),
borderRadius: BorderRadius.circular(8),
border: data.isCurrentUser
? Border.all(color: const Color(0xFFD4AF37), width: 1)
: null,
),
),
// +
SizedBox(
width: stickmanLeftPosition - nicknameAreaWidth,
),
//
Column(
mainAxisSize: MainAxisSize.min,
children: [
//
Container(
constraints: const BoxConstraints(maxWidth: 60),
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: data.isCurrentUser
? const Color(0xFFD4AF37)
: const Color(0xFF8B5A2B),
borderRadius: BorderRadius.circular(8),
),
child: FittedBox(
fit: BoxFit.scaleDown,
child: Text(
'${_formatNumber(data.completedCount)}',
style: const TextStyle(
fontSize: 9,
fontFamily: 'Inter',
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
),
),
const SizedBox(height: 2),
//
RunningStickman(
size: 36,
child: Text(
data.nickname,
style: TextStyle(
fontSize: 9,
fontFamily: 'Inter',
fontWeight: data.isCurrentUser ? FontWeight.w600 : FontWeight.w400,
color: data.isCurrentUser
? const Color(0xFFD4AF37)
: const Color(0xFF5D4037),
),
],
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
),
],
),
),
),
//
Positioned(
left: stickmanCenterX - 30, // 60
top: verticalPosition - bounce,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
//
Container(
constraints: const BoxConstraints(maxWidth: 60),
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: data.isCurrentUser
? const Color(0xFFD4AF37)
: const Color(0xFF8B5A2B),
borderRadius: BorderRadius.circular(8),
),
child: FittedBox(
fit: BoxFit.scaleDown,
child: Text(
'${_formatNumber(data.completedCount)}',
style: const TextStyle(
fontSize: 9,
fontFamily: 'Inter',
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
),
),
const SizedBox(height: 2),
//
RunningStickman(
size: 36,
color: data.isCurrentUser
? const Color(0xFFD4AF37)
: const Color(0xFF5D4037),
),
],
),
),
],
);
},
);