Unverified Commit 8dcae5ac authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

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>
parent c3552191
...@@ -879,7 +879,7 @@ class RenderListWheelViewport ...@@ -879,7 +879,7 @@ class RenderListWheelViewport
// renderChildrenOutsideViewport is true. Otherwise, only children within // renderChildrenOutsideViewport is true. Otherwise, only children within
// suitable angles (via _first/lastVisibleLayoutOffset) reach the paint // suitable angles (via _first/lastVisibleLayoutOffset) reach the paint
// phase. // 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; return;
} }
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
library; library;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../rendering/rendering_tester.dart' show TestCallbackPainter, TestClipPaintingContext; import '../rendering/rendering_tester.dart' show TestCallbackPainter, TestClipPaintingContext;
...@@ -1883,4 +1883,28 @@ void main() { ...@@ -1883,4 +1883,28 @@ void main() {
expect(tester.layers.whereType<OpacityLayer>(), hasLength(1)); 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);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment