Skip to content

Commit 9bd6ff3

Browse files
authored
fix a CupertinoDatePicker bug (#112697)
1 parent 529184b commit 9bd6ff3

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

packages/flutter/lib/src/rendering/list_wheel_viewport.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,14 @@ class RenderListWheelViewport
681681
/// by [childManager].
682682
@override
683683
void performLayout() {
684-
// Apply the dimensions first in case it changes the scroll offset which
685-
// determines what should be shown.
686684
offset.applyViewportDimension(_viewportExtent);
687-
offset.applyContentDimensions(_minEstimatedScrollExtent, _maxEstimatedScrollExtent);
685+
// Apply the content dimensions first if it has exact dimensions in case it
686+
// changes the scroll offset which determines what should be shown. Such as
687+
// if the child count decrease, we should correct the pixels first, otherwise,
688+
// it may be shown blank null children.
689+
if (childManager.childCount != null) {
690+
offset.applyContentDimensions(_minEstimatedScrollExtent, _maxEstimatedScrollExtent);
691+
}
688692

689693
// The height, in pixel, that children will be visible and might be laid out
690694
// and painted.

packages/flutter/test/widgets/list_wheel_scroll_view_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,44 @@ void main() {
288288
});
289289

290290
group('layout', () {
291+
testWidgets('Flings with high velocity should not break the children lower and upper limits', (WidgetTester tester) async {
292+
// Regression test for https://github.com/flutter/flutter/issues/112526
293+
final FixedExtentScrollController controller = FixedExtentScrollController();
294+
Widget buildFrame() {
295+
return Directionality(
296+
textDirection: TextDirection.ltr,
297+
child: ListWheelScrollView.useDelegate(
298+
physics: const FixedExtentScrollPhysics(),
299+
controller: controller,
300+
itemExtent: 400.0,
301+
onSelectedItemChanged: (_) { },
302+
childDelegate: ListWheelChildBuilderDelegate(
303+
builder: (BuildContext context, int index) {
304+
if (index < 0 || index > 5) {
305+
return null;
306+
}
307+
return SizedBox(
308+
width: 400.0,
309+
height: 400.0,
310+
child: Text(index.toString()),
311+
);
312+
},
313+
),
314+
),
315+
);
316+
}
317+
318+
await tester.pumpWidget(buildFrame());
319+
expect(tester.renderObject(find.text('0')).attached, true);
320+
expect(tester.renderObject(find.text('1')).attached, true);
321+
expect(find.text('2'), findsNothing);
322+
expect(controller.selectedItem, 0);
323+
324+
// Flings with high velocity and stop at the child boundary.
325+
await tester.fling(find.byType(ListWheelScrollView), const Offset(0.0, 40000.0), 8000.0);
326+
expect(controller.selectedItem, 0);
327+
}, variant: TargetPlatformVariant(TargetPlatform.values.toSet()));
328+
291329
// Regression test for https://github.com/flutter/flutter/issues/90953
292330
testWidgets('ListWheelScrollView childDelegate update test 2', (WidgetTester tester) async {
293331
final FixedExtentScrollController controller = FixedExtentScrollController( initialItem: 2 );

0 commit comments

Comments
 (0)