Fix ListWheelScrollView in an AnimatedContainer with zero height throw an error (#141372)

fixes [`ListWheelScrollView` Throws Unexpected Error Inside `AnimatedContainer`](https://github.com/flutter/flutter/issues/140780)
fixes [`CupertinoDatePicker` throw exception when parent height is 0](https://github.com/flutter/flutter/issues/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>
This commit is contained in:
Taha Tesser 2024-01-11 20:26:04 +02:00 committed by GitHub
parent c355219154
commit 8dcae5ace4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View file

@ -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;
}

View file

@ -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;
@ -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);
});
}