Skip to content

Commit

Permalink
Fix ListWheelScrollView in an AnimatedContainer with zero height …
Browse files Browse the repository at this point in the history
…throw an error (#141372)

fixes [`ListWheelScrollView` Throws Unexpected Error Inside `AnimatedContainer`](flutter/flutter#140780)
fixes [`CupertinoDatePicker` throw exception when parent height is 0](flutter/flutter#55630)

### Code sample

<details>
<summary>expand to view the code sample</summary> 

```dart
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @OverRide
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: AnimatedContainer(
          height: 0,
          duration: Duration.zero,
          child: ListWheelScrollView(
            itemExtent: 20.0,
            children: <Widget>[
              for (int i = 0; i < 20; i++) Container(),
            ],
          ),
        ),
      ),
    );
  }
}
```

</details>
  • Loading branch information
TahaTesser authored Jan 11, 2024
1 parent c355219 commit 8dcae5a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ class RenderListWheelViewport
// renderChildrenOutsideViewport is true. Otherwise, only children within
// suitable angles (via _first/lastVisibleLayoutOffset) reach the paint
// phase.
if (angle > math.pi / 2.0 || angle < -math.pi / 2.0) {
if (angle > math.pi / 2.0 || angle < -math.pi / 2.0 || angle.isNaN) {
return;
}

Expand Down
26 changes: 25 additions & 1 deletion packages/flutter/test/widgets/list_wheel_scroll_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
library;

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

import '../rendering/rendering_tester.dart' show TestCallbackPainter, TestClipPaintingContext;
Expand Down Expand Up @@ -1883,4 +1883,28 @@ void main() {

expect(tester.layers.whereType<OpacityLayer>(), hasLength(1));
});

// This is a regression test for https://github.com/flutter/flutter/issues/140780.
testWidgets('ListWheelScrollView in an AnimatedContainer with zero height does not throw an error',
(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: AnimatedContainer(
height: 0,
duration: Duration.zero,
child: ListWheelScrollView(
itemExtent: 20.0,
children: <Widget>[
for (int i = 0; i < 20; i++)
Container(),
],
),
),
),
),
);

expect(tester.takeException(), isNull);
});
}

0 comments on commit 8dcae5a

Please sign in to comment.