File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -1340,7 +1340,7 @@ class _CarouselPosition extends ScrollPositionWithSingleContext implements _Caro
1340
1340
if (_itemExtent == value) {
1341
1341
return ;
1342
1342
}
1343
- if (hasPixels) {
1343
+ if (hasPixels && _itemExtent != null ) {
1344
1344
final double leadingItem = getItemFromPixels (pixels, viewportDimension);
1345
1345
final double newPixel = getPixelsFromItem (leadingItem, flexWeights, value);
1346
1346
forcePixels (newPixel);
Original file line number Diff line number Diff line change @@ -1149,6 +1149,50 @@ void main() {
1149
1149
expect (getItem (5 ), findsOneWidget);
1150
1150
expect (tester.getRect (getItem (5 )).width, difference);
1151
1151
});
1152
+
1153
+ testWidgets ('Updating CarouselView does not cause exception' , (WidgetTester tester) async {
1154
+ // Regression test for https://github.com/flutter/flutter/issues/152787
1155
+ bool isLight = true ;
1156
+ await tester.pumpWidget (
1157
+ StatefulBuilder (
1158
+ builder: (BuildContext context, StateSetter setState) {
1159
+ return MaterialApp (
1160
+ theme: Theme .of (context).copyWith (
1161
+ brightness: isLight ? Brightness .light : Brightness .dark,
1162
+ ),
1163
+ home: Scaffold (
1164
+ appBar: AppBar (
1165
+ actions: < Widget > [
1166
+ Switch (
1167
+ value: isLight,
1168
+ onChanged: (bool value) {
1169
+ setState (() {
1170
+ isLight = value;
1171
+ });
1172
+ }
1173
+ )
1174
+ ],
1175
+ ),
1176
+ body: CarouselView (
1177
+ itemExtent: 100 ,
1178
+ children: List <Widget >.generate (10 , (int index) {
1179
+ return Center (
1180
+ child: Text ('Item $index ' ),
1181
+ );
1182
+ }),
1183
+ ),
1184
+ ),
1185
+ );
1186
+ }
1187
+ )
1188
+ );
1189
+ await tester.pumpAndSettle ();
1190
+ await tester.tap (find.byType (Switch ));
1191
+ await tester.pumpAndSettle ();
1192
+
1193
+ // No exception.
1194
+ expect (tester.takeException (), isNull);
1195
+ });
1152
1196
}
1153
1197
1154
1198
Finder getItem (int index) {
You can’t perform that action at this time.
0 commit comments