Fixes an issue where itemExtent was incorrectly assigned to renderObject.minExtent (#153805)
Fixes #153694. Previously, when state was updated, the updateRenderObject method incorrectly assigned itemExtent to renderObject.minExtent, which unintentionally overrode the intended default behavior.
This commit is contained in:
parent
056c40f55b
commit
d9dda9d08f
@ -529,7 +529,7 @@ class _SliverFixedExtentCarousel extends SliverMultiBoxAdaptorWidget {
|
||||
@override
|
||||
void updateRenderObject(BuildContext context, _RenderSliverFixedExtentCarousel renderObject) {
|
||||
renderObject.maxExtent = itemExtent;
|
||||
renderObject.minExtent = itemExtent;
|
||||
renderObject.minExtent = minExtent;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1193,6 +1193,49 @@ void main() {
|
||||
// No exception.
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('The shrinkExtent should keep the same when the item is tapped', (WidgetTester tester) async {
|
||||
final List<Widget> children = List<Widget>.generate(20, (int index) {
|
||||
return Center(
|
||||
child: Text('Item $index'),
|
||||
);
|
||||
});
|
||||
|
||||
await tester.pumpWidget(
|
||||
StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setState) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxHeight: 200),
|
||||
child: CarouselView(
|
||||
itemExtent: 330,
|
||||
onTap: (int idx) => setState(() { }),
|
||||
children: children,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.getRect(getItem(0)).width, 330.0);
|
||||
|
||||
final Finder item1 = find.text('Item 1');
|
||||
await tester.tap(find.ancestor(of: item1, matching: find.byType(Stack)));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.getRect(getItem(0)).width, 330.0);
|
||||
expect(tester.getRect(getItem(1)).width, 330.0);
|
||||
// This should be less than 330.0 because the item is shrunk; width is 800.0 - 330.0 - 330.0
|
||||
expect(tester.getRect(getItem(2)).width, 140.0);
|
||||
});
|
||||
}
|
||||
|
||||
Finder getItem(int index) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user