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 {