From 030e2a5517c378cbc15a6eb7505a0a1508fe63e3 Mon Sep 17 00:00:00 2001 From: flutteractionsbot <154381524+flutteractionsbot@users.noreply.github.com> Date: Thu, 24 Apr 2025 17:08:49 -0700 Subject: [PATCH] [CP-beta]Unbreak https://github.com/flutter/flutter/pull/164034 (#167736) This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request) Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request. ### Issue Link: What is the link to the issue this cherry-pick is addressing? https://github.com/flutter/flutter/issues/167247 We identified a breaking change in beta, this change un-breaks it. ### Changelog Description: Explain this cherry pick in one line that is accessible to most Flutter developers. See [best practices](https://github.com/flutter/flutter/blob/main/docs/releases/Hotfix-Documentation-Best-Practices.md) for examples Restore RenderConstrainedLayoutBuilder with default layoutInfo implementation to undo a breaking change. ### Impact Description: What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)? Does it impact development (ex. flutter doctor crashes when Android Studio is installed), or the shipping production app (the app crashes on launch) A class was renamed, which left developers with a "class not found" error as their only guide. ### Workaround: Is there a workaround for this issue? Nope. ### Risk: What is the risk level of this cherry-pick? ### Test Coverage: Are you confident that your fix is well-tested by automated tests? ### Validation Steps: What are the steps to validate that this fix works? Classes that mixin RenderConstrainedLayoutBuilder are no longer broken and the code can compile. --- .../lib/src/widgets/layout_builder.dart | 23 ++++++++++++------- .../src/widgets/sliver_layout_builder.dart | 8 ++----- .../test/widgets/layout_builder_test.dart | 4 ---- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/packages/flutter/lib/src/widgets/layout_builder.dart b/packages/flutter/lib/src/widgets/layout_builder.dart index 79980bb458..45e9608f59 100644 --- a/packages/flutter/lib/src/widgets/layout_builder.dart +++ b/packages/flutter/lib/src/widgets/layout_builder.dart @@ -302,8 +302,12 @@ class _LayoutBuilderElement extends RenderObjectElement { /// Provides a [layoutCallback] implementation which, if needed, invokes /// [AbstractLayoutBuilder]'s builder callback. /// -/// Implementers must provide a [layoutInfo] implementation that is safe to -/// access in [layoutCallback], which is called in [performLayout]. +/// Implementers can override the [layoutInfo] implementation with a value +/// that is safe to access in [layoutCallback], which is called in +/// [performLayout]. The default [layoutInfo] returns the incoming +/// [Constraints]. +/// +/// This mixin replaces [RenderConstrainedLayoutBuilder]. mixin RenderAbstractLayoutBuilderMixin on RenderObjectWithChildMixin, RenderObjectWithLayoutCallbackMixin { LayoutCallback? _callback; @@ -334,11 +338,18 @@ mixin RenderAbstractLayoutBuilderMixin constraints as LayoutInfoType; } +/// Generic mixin for [RenderObject]s created by an [AbstractLayoutBuilder] with +/// the the same `LayoutInfoType`. +/// +/// Use [RenderAbstractLayoutBuilderMixin] instead, which replaces this mixin. +typedef RenderConstrainedLayoutBuilder = + RenderAbstractLayoutBuilderMixin; + /// Builds a widget tree that can depend on the parent widget's size. /// /// Similar to the [Builder] widget except that the framework calls the [builder] @@ -476,10 +487,6 @@ class _RenderLayoutBuilder extends RenderBox return true; } - - @protected - @override - BoxConstraints get layoutInfo => constraints; } FlutterErrorDetails _reportException( diff --git a/packages/flutter/lib/src/widgets/sliver_layout_builder.dart b/packages/flutter/lib/src/widgets/sliver_layout_builder.dart index a7daaae35d..dd06fbd1ed 100644 --- a/packages/flutter/lib/src/widgets/sliver_layout_builder.dart +++ b/packages/flutter/lib/src/widgets/sliver_layout_builder.dart @@ -29,7 +29,7 @@ class SliverLayoutBuilder extends ConstrainedLayoutBuilder { const SliverLayoutBuilder({super.key, required super.builder}); @override - RenderAbstractLayoutBuilderMixin createRenderObject( + RenderConstrainedLayoutBuilder createRenderObject( BuildContext context, ) => _RenderSliverLayoutBuilder(); } @@ -38,17 +38,13 @@ class _RenderSliverLayoutBuilder extends RenderSliver with RenderObjectWithChildMixin, RenderObjectWithLayoutCallbackMixin, - RenderAbstractLayoutBuilderMixin { + RenderConstrainedLayoutBuilder { @override double childMainAxisPosition(RenderObject child) { assert(child == this.child); return 0; } - @protected - @override - SliverConstraints get layoutInfo => constraints; - @override void performLayout() { runLayoutCallback(); diff --git a/packages/flutter/test/widgets/layout_builder_test.dart b/packages/flutter/test/widgets/layout_builder_test.dart index e11dfd5202..2133ab111f 100644 --- a/packages/flutter/test/widgets/layout_builder_test.dart +++ b/packages/flutter/test/widgets/layout_builder_test.dart @@ -1067,10 +1067,6 @@ class _RenderSmartLayoutBuilder extends RenderProxyBox onChildWasPainted(extraOffset); } } - - @protected - @override - BoxConstraints get layoutInfo => constraints; } class _LayoutSpy extends LeafRenderObjectWidget {