diff --git a/packages/flutter/lib/src/widgets/overlay.dart b/packages/flutter/lib/src/widgets/overlay.dart index c75b22032c..6f8ae86385 100644 --- a/packages/flutter/lib/src/widgets/overlay.dart +++ b/packages/flutter/lib/src/widgets/overlay.dart @@ -2613,9 +2613,6 @@ class _OverlayChildLayoutBuilder extends AbstractLayoutBuilder createRenderObject( BuildContext context, ) => _RenderLayoutBuilder(); - - @override - bool updateShouldRebuild(_OverlayChildLayoutBuilder oldWidget) => oldWidget.builder != builder; } // A RenderBox that: @@ -2709,14 +2706,10 @@ class _RenderLayoutBuilder extends RenderProxyBox int? _callbackId; @override void performLayout() { - late OverlayChildLayoutInfo newLayoutInfo; // The invokeLayoutCallback allows arbitrary access to the sizes of // RenderBoxes the we know that have finished doing layout. - invokeLayoutCallback((_) => newLayoutInfo = _computeNewLayoutInfo()); - if (newLayoutInfo != _layoutInfo) { - _layoutInfo = newLayoutInfo; - rebuildIfNecessary(); - } + invokeLayoutCallback((_) => _layoutInfo = _computeNewLayoutInfo()); + rebuildIfNecessary(); assert(_callbackId == null); _callbackId ??= SchedulerBinding.instance.scheduleFrameCallback( _frameCallback, diff --git a/packages/flutter/test/scheduler/scheduler_test.dart b/packages/flutter/test/scheduler/scheduler_test.dart index 2244612cce..60febe3837 100644 --- a/packages/flutter/test/scheduler/scheduler_test.dart +++ b/packages/flutter/test/scheduler/scheduler_test.dart @@ -38,6 +38,20 @@ class TestSchedulerBinding extends BindingBase with SchedulerBinding, ServicesBi List> getEventsDispatched(String eventKind) { return eventsDispatched.putIfAbsent(eventKind, () => >[]); } + + void tearDown() { + additionalHandleBeginFrame = null; + additionalHandleDrawFrame = null; + PlatformDispatcher.instance + ..onBeginFrame = null + ..onDrawFrame = null; + } + + /// Ensures callbacks for [PlatformDispatcher.onBeginFrame] and + /// [PlatformDispatcher.onDrawFrame] are registered. + void registerFrameCallbacks() { + ensureFrameCallbacksRegistered(); + } } class TestStrategy { @@ -55,13 +69,7 @@ void main() { scheduler = TestSchedulerBinding(); }); - tearDown(() { - scheduler.additionalHandleBeginFrame = null; - scheduler.additionalHandleDrawFrame = null; - PlatformDispatcher.instance - ..onBeginFrame = null - ..onDrawFrame = null; - }); + tearDown(() => scheduler.tearDown()); test('Tasks are executed in the right order', () { final TestStrategy strategy = TestStrategy(); @@ -301,6 +309,7 @@ void main() { warmUpBeginFrame(); + scheduler.registerFrameCallbacks(); // Simulate an animation frame firing between warm-up begin frame and warm-up draw frame. // Expect a timer that reschedules the frame. expect(scheduler.hasScheduledFrame, isFalse); diff --git a/packages/flutter/test/widgets/overlay_layout_builder_test.dart b/packages/flutter/test/widgets/overlay_layout_builder_test.dart index 90a823f787..892b8d1645 100644 --- a/packages/flutter/test/widgets/overlay_layout_builder_test.dart +++ b/packages/flutter/test/widgets/overlay_layout_builder_test.dart @@ -140,6 +140,51 @@ void main() { expect(regularChildSize, childSize); }); + testWidgets('builder callback is called when OverlayPortal rebuilds', ( + WidgetTester tester, + ) async { + late StateSetter setState; + Color color = const Color(0x12345678); + late final OverlayEntry overlayEntry; + addTearDown( + () => + overlayEntry + ..remove() + ..dispose(), + ); + + Widget builder(BuildContext _, OverlayChildLayoutInfo _) => ColoredBox(color: color); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Overlay( + initialEntries: [ + overlayEntry = OverlayEntry( + builder: (BuildContext context) { + return StatefulBuilder( + builder: (BuildContext context, StateSetter setter) { + setState = setter; + return OverlayPortal.overlayChildLayoutBuilder( + controller: controller1, + overlayChildBuilder: builder, + child: const SizedBox(), + ); + }, + ); + }, + ), + ], + ), + ), + ); + expect(find.byType(ColoredBox), paints..rect(color: color)); + + setState(() => color = const Color(0x87654321)); + await tester.pump(); + expect(find.byType(ColoredBox), paints..rect(color: color)); + }); + testWidgets('Positioned works in the builder', (WidgetTester tester) async { late final OverlayEntry overlayEntry; addTearDown(