Skip to content

Commit 7491d4d

Browse files
Fix FortuneBar indicator dynamic resizing
- Changed FortuneBar to use a fixed `unitWidth` for the indicator size instead of resizing it dynamically based on the item passing under it. - Wrapped indicator child in `Center` to allow it to choose its size or fill the fixed slot. - Removed `_getIndicatorWidth`.
1 parent 8246a81 commit 7491d4d

1 file changed

Lines changed: 4 additions & 36 deletions

File tree

lib/src/bar/fortune_bar.dart

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -145,34 +145,6 @@ class _FortuneBarState extends State<FortuneBar> with SingleTickerProviderStateM
145145
// animateFirst is only for initState
146146
}
147147

148-
double _getIndicatorWidth(
149-
Alignment alignment,
150-
double scrollOffset,
151-
List<double> itemWidths,
152-
double screenWidth,
153-
double totalWidth,
154-
) {
155-
final centerOffset = screenWidth / 2;
156-
final P = scrollOffset % totalWidth;
157-
final relativeP = P < 0 ? P + totalWidth : P;
158-
159-
final screenX = (alignment.x + 1) / 2 * screenWidth;
160-
final distFromCenter = screenX - centerOffset;
161-
162-
var stripPos = relativeP + distFromCenter;
163-
stripPos %= totalWidth;
164-
if (stripPos < 0) stripPos += totalWidth;
165-
166-
double currentPos = 0;
167-
for (final w in itemWidths) {
168-
if (stripPos < currentPos + w) {
169-
return w;
170-
}
171-
currentPos += w;
172-
}
173-
return itemWidths.isEmpty ? 0 : itemWidths.last;
174-
}
175-
176148
@override
177149
Widget build(BuildContext context) {
178150
final theme = Theme.of(context);
@@ -254,15 +226,11 @@ class _FortuneBarState extends State<FortuneBar> with SingleTickerProviderStateM
254226
child: Align(
255227
alignment: it.alignment,
256228
child: SizedBox(
257-
width: _getIndicatorWidth(
258-
it.alignment.resolve(Directionality.of(context)),
259-
scrollOffset,
260-
itemWidths,
261-
size.width,
262-
totalWidth,
263-
),
229+
width: unitWidth,
264230
height: widget.height,
265-
child: it.child,
231+
child: Center(
232+
child: it.child,
233+
),
266234
),
267235
),
268236
),

0 commit comments

Comments
 (0)