fix(mobile): 修复火柴人组件布局错误,避免嵌套Stack

🤖 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 02:53:21 -08:00
parent 0623169d19
commit 27bee6d7f1
1 changed files with 112 additions and 113 deletions

View File

@ -188,9 +188,8 @@ class _StickmanRaceWidgetState extends State<StickmanRaceWidget>
builder: (context, constraints) { builder: (context, constraints) {
final containerWidth = constraints.maxWidth; final containerWidth = constraints.maxWidth;
return Stack( // Positioned widgets
clipBehavior: Clip.none, final List<Widget> children = [
children: [
// 线 // 线
Positioned.fill( Positioned.fill(
child: CustomPaint( child: CustomPaint(
@ -199,11 +198,12 @@ class _StickmanRaceWidgetState extends State<StickmanRaceWidget>
), ),
), ),
), ),
];
// //
...List.generate(trackCount, (index) { for (int index = 0; index < trackCount; index++) {
final verticalPosition = index * trackHeight + 10 + trackHeight / 2 - 16; final verticalPosition = index * trackHeight + 10 + trackHeight / 2 - 16;
return Positioned( children.add(Positioned(
right: 8, right: 8,
top: verticalPosition, top: verticalPosition,
child: const Icon( child: const Icon(
@ -211,24 +211,32 @@ class _StickmanRaceWidgetState extends State<StickmanRaceWidget>
color: Colors.red, color: Colors.red,
size: 24, size: 24,
), ),
); ));
}), }
// //
...sortedRankings.asMap().entries.map((entry) { for (int index = 0; index < sortedRankings.length; index++) {
final index = entry.key; final data = sortedRankings[index];
final data = entry.value; final widgets = _buildStickmanWidgets(data, index, sortedRankings.length, raceTrackHeight, containerWidth);
return _buildStickman(data, index, sortedRankings.length, raceTrackHeight, containerWidth); children.addAll(widgets);
}), }
],
return AnimatedBuilder(
animation: _bounceController,
builder: (context, child) {
return Stack(
clipBehavior: Clip.none,
children: children,
);
},
); );
}, },
), ),
); );
} }
/// /// Positioned widgets
Widget _buildStickman(StickmanRankingData data, int rank, int total, double raceTrackHeight, double containerWidth) { List<Widget> _buildStickmanWidgets(StickmanRankingData data, int rank, int total, double raceTrackHeight, double containerWidth) {
// (0.0 - 1.0) // (0.0 - 1.0)
final progress = data.progress; final progress = data.progress;
@ -237,22 +245,16 @@ class _StickmanRaceWidgetState extends State<StickmanRaceWidget>
final trackHeight = usableHeight / total; final trackHeight = usableHeight / total;
final verticalPosition = rank * trackHeight + 10; final verticalPosition = rank * trackHeight + 10;
// 50maxWidth:60 // :
// : right=8, width=24, = containerWidth - 32 // = 70 ()
// : stickmanLeft + 50 = containerWidth - 32 // = - = (containerWidth - 32) - 50 = containerWidth - 82
// endX = containerWidth - 82
const double startX = 70.0; const double startX = 70.0;
final double endX = containerWidth - 82.0; final double endX = containerWidth - 82.0;
final double stickmanLeft = startX + (endX - startX) * progress; final double stickmanLeft = startX + (endX - startX) * progress;
return AnimatedBuilder(
animation: _bounceController,
builder: (context, child) {
final bounce = _bounceController.value * 3; final bounce = _bounceController.value * 3;
return Stack( return [
clipBehavior: Clip.none,
children: [
// - // -
Positioned( Positioned(
left: 0, left: 0,
@ -327,10 +329,7 @@ class _StickmanRaceWidgetState extends State<StickmanRaceWidget>
], ],
), ),
), ),
], ];
);
},
);
} }
/// ///