Skip to content

Commit d9dda9d

Browse files
authored
Fixes an issue where itemExtent was incorrectly assigned to renderObject.minExtent (flutter#153805)
Fixes flutter#153694. Previously, when state was updated, the updateRenderObject method incorrectly assigned itemExtent to renderObject.minExtent, which unintentionally overrode the intended default behavior.
1 parent 056c40f commit d9dda9d

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

packages/flutter/lib/src/material/carousel.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ class _SliverFixedExtentCarousel extends SliverMultiBoxAdaptorWidget {
529529
@override
530530
void updateRenderObject(BuildContext context, _RenderSliverFixedExtentCarousel renderObject) {
531531
renderObject.maxExtent = itemExtent;
532-
renderObject.minExtent = itemExtent;
532+
renderObject.minExtent = minExtent;
533533
}
534534
}
535535

packages/flutter/test/material/carousel_test.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,49 @@ void main() {
11931193
// No exception.
11941194
expect(tester.takeException(), isNull);
11951195
});
1196+
1197+
testWidgets('The shrinkExtent should keep the same when the item is tapped', (WidgetTester tester) async {
1198+
final List<Widget> children = List<Widget>.generate(20, (int index) {
1199+
return Center(
1200+
child: Text('Item $index'),
1201+
);
1202+
});
1203+
1204+
await tester.pumpWidget(
1205+
StatefulBuilder(
1206+
builder: (BuildContext context, StateSetter setState) {
1207+
return MaterialApp(
1208+
home: Scaffold(
1209+
body: Center(
1210+
child: ConstrainedBox(
1211+
constraints: const BoxConstraints(maxHeight: 200),
1212+
child: CarouselView(
1213+
itemExtent: 330,
1214+
onTap: (int idx) => setState(() { }),
1215+
children: children,
1216+
),
1217+
),
1218+
),
1219+
),
1220+
);
1221+
}
1222+
)
1223+
);
1224+
1225+
await tester.pumpAndSettle();
1226+
1227+
expect(tester.getRect(getItem(0)).width, 330.0);
1228+
1229+
final Finder item1 = find.text('Item 1');
1230+
await tester.tap(find.ancestor(of: item1, matching: find.byType(Stack)));
1231+
1232+
await tester.pumpAndSettle();
1233+
1234+
expect(tester.getRect(getItem(0)).width, 330.0);
1235+
expect(tester.getRect(getItem(1)).width, 330.0);
1236+
// This should be less than 330.0 because the item is shrunk; width is 800.0 - 330.0 - 330.0
1237+
expect(tester.getRect(getItem(2)).width, 140.0);
1238+
});
11961239
}
11971240

11981241
Finder getItem(int index) {

0 commit comments

Comments
 (0)