Fix needsCompositing propagation from child widgets. (#32717)

This fixes propagation of needsCompositing from child widgets.

When needsCompositing is turned on by a child widget, it necessarily sets the needsCompositing bit of its parent widget, but RenderPointerListener was ignoring that piece of information and only turning on compositing if it thought it needed it for itself.

This corrects that, and adds a test for the condition, and updates a test that was affected by the change.

Fixes #32525 (again)
diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart
index 7f0cf9d..3a059c2 100644
--- a/packages/flutter/lib/src/rendering/proxy_box.dart
+++ b/packages/flutter/lib/src/rendering/proxy_box.dart
@@ -2654,7 +2654,7 @@
   bool get _hasActiveAnnotation => _hoverAnnotation != null && _mouseIsConnected;
 
   @override
-  bool get needsCompositing => _hasActiveAnnotation;
+  bool get needsCompositing => super.needsCompositing || _hasActiveAnnotation;
 
   @override
   void paint(PaintingContext context, Offset offset) {
diff --git a/packages/flutter/test/widgets/keep_alive_test.dart b/packages/flutter/test/widgets/keep_alive_test.dart
index 15e39a3..f74307a 100644
--- a/packages/flutter/test/widgets/keep_alive_test.dart
+++ b/packages/flutter/test/widgets/keep_alive_test.dart
@@ -234,12 +234,14 @@
       '       │   repaints)\n'
       '       │\n'
       '       └─child: _RenderScrollSemantics#00000\n'
+      '         │ needs compositing\n'
       '         │ parentData: <none> (can use size)\n'
       '         │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
       '         │ semantic boundary\n'
       '         │ size: Size(800.0, 600.0)\n'
       '         │\n'
       '         └─child: RenderPointerListener#00000\n'
+      '           │ needs compositing\n'
       '           │ parentData: <none> (can use size)\n'
       '           │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
       '           │ size: Size(800.0, 600.0)\n'
@@ -247,6 +249,7 @@
       '           │ listeners: signal\n'
       '           │\n'
       '           └─child: RenderSemanticsGestureHandler#00000\n'
+      '             │ needs compositing\n'
       '             │ parentData: <none> (can use size)\n'
       '             │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
       '             │ size: Size(800.0, 600.0)\n'
@@ -377,12 +380,14 @@
       '       │   repaints)\n'
       '       │\n'
       '       └─child: _RenderScrollSemantics#00000\n'
+      '         │ needs compositing\n'
       '         │ parentData: <none> (can use size)\n'
       '         │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
       '         │ semantic boundary\n'
       '         │ size: Size(800.0, 600.0)\n'
       '         │\n'
       '         └─child: RenderPointerListener#00000\n'
+      '           │ needs compositing\n'
       '           │ parentData: <none> (can use size)\n'
       '           │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
       '           │ size: Size(800.0, 600.0)\n'
@@ -390,6 +395,7 @@
       '           │ listeners: signal\n'
       '           │\n'
       '           └─child: RenderSemanticsGestureHandler#00000\n'
+      '             │ needs compositing\n'
       '             │ parentData: <none> (can use size)\n'
       '             │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
       '             │ size: Size(800.0, 600.0)\n'
diff --git a/packages/flutter/test/widgets/listener_test.dart b/packages/flutter/test/widgets/listener_test.dart
index aba6980..b4da4b5 100644
--- a/packages/flutter/test/widgets/listener_test.dart
+++ b/packages/flutter/test/widgets/listener_test.dart
@@ -391,6 +391,28 @@
       await gesture.removePointer();
     });
 
+    testWidgets('needsCompositing set when parent class needsCompositing is set', (WidgetTester tester) async {
+      await tester.pumpWidget(
+        Listener(
+          onPointerEnter: (PointerEnterEvent _) {},
+          child: const Opacity(opacity: 0.5, child: Placeholder()),
+        ),
+      );
+
+      RenderPointerListener listener = tester.renderObject(find.byType(Listener).first);
+      expect(listener.needsCompositing, isTrue);
+
+      await tester.pumpWidget(
+        Listener(
+          onPointerEnter: (PointerEnterEvent _) {},
+          child: const Placeholder(),
+        ),
+      );
+
+      listener = tester.renderObject(find.byType(Listener).first);
+      expect(listener.needsCompositing, isFalse);
+    });
+
     testWidgets('works with transform', (WidgetTester tester) async {
       // Regression test for https://github.com/flutter/flutter/issues/31986.
       final Key key = UniqueKey();