Skip to content

Commit bc688cf

Browse files
authored
Make constraints a covariant argument in RenderBox.computeDryLayout() (#136432)
Some render box subclasses have a specific layout contract that is tightly coupled with other render box subclasses (e.g. two private classes in a local project file). In these cases, it is also possible that they use a constraints object that is a subclass of `BoxConstraints`. To allow for this, this change makes the `constraints` argument to `RenderBox.computeDryLayout()` a covariant argument. For completeness' sake, this updates the other render objects in the rendering package to also use the covariant keyword for this argument.
1 parent 0f08288 commit bc688cf

23 files changed

+113
-38
lines changed

packages/flutter/lib/src/rendering/animated_size.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
264264
}
265265

266266
@override
267-
Size computeDryLayout(BoxConstraints constraints) {
267+
@protected
268+
Size computeDryLayout(covariant BoxConstraints constraints) {
268269
if (child == null || constraints.isTight) {
269270
return constraints.smallest;
270271
}

packages/flutter/lib/src/rendering/box.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1906,7 +1906,7 @@ abstract class RenderBox extends RenderObject {
19061906
/// [debugCannotComputeDryLayout] from within an assert and return a dummy
19071907
/// value of `const Size(0, 0)`.
19081908
@protected
1909-
Size computeDryLayout(BoxConstraints constraints) {
1909+
Size computeDryLayout(covariant BoxConstraints constraints) {
19101910
assert(debugCannotComputeDryLayout(
19111911
error: FlutterError.fromParts(<DiagnosticsNode>[
19121912
ErrorSummary('The ${objectRuntimeType(this, 'RenderBox')} class does not implement "computeDryLayout".'),

packages/flutter/lib/src/rendering/custom_layout.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,8 @@ class RenderCustomMultiChildLayoutBox extends RenderBox
393393
}
394394

395395
@override
396-
Size computeDryLayout(BoxConstraints constraints) {
396+
@protected
397+
Size computeDryLayout(covariant BoxConstraints constraints) {
397398
return _getSize(constraints);
398399
}
399400

packages/flutter/lib/src/rendering/editable.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,7 +2270,8 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
22702270
bool get _canComputeIntrinsics => _canComputeIntrinsicsCached ??= _canComputeDryLayoutForInlineWidgets();
22712271

22722272
@override
2273-
Size computeDryLayout(BoxConstraints constraints) {
2273+
@protected
2274+
Size computeDryLayout(covariant BoxConstraints constraints) {
22742275
if (!_canComputeIntrinsics) {
22752276
assert(debugCannotComputeDryLayout(
22762277
reason: 'Dry layout not available for alignments that require baseline.',
@@ -2630,7 +2631,8 @@ class _RenderEditableCustomPaint extends RenderBox {
26302631
}
26312632

26322633
@override
2633-
Size computeDryLayout(BoxConstraints constraints) => constraints.biggest;
2634+
@protected
2635+
Size computeDryLayout(covariant BoxConstraints constraints) => constraints.biggest;
26342636
}
26352637

26362638
/// An interface that paints within a [RenderEditable]'s bounds, above or

packages/flutter/lib/src/rendering/error.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import 'dart:ui' as ui show Paragraph, ParagraphBuilder, ParagraphConstraints, ParagraphStyle, TextStyle;
66

7+
import 'package:flutter/foundation.dart';
8+
79
import 'box.dart';
810
import 'object.dart';
911

@@ -77,7 +79,8 @@ class RenderErrorBox extends RenderBox {
7779
bool hitTestSelf(Offset position) => true;
7880

7981
@override
80-
Size computeDryLayout(BoxConstraints constraints) {
82+
@protected
83+
Size computeDryLayout(covariant BoxConstraints constraints) {
8184
return constraints.constrain(const Size(_kMaxWidth, _kMaxHeight));
8285
}
8386

packages/flutter/lib/src/rendering/flex.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,8 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
653653
}
654654

655655
@override
656-
Size computeDryLayout(BoxConstraints constraints) {
656+
@protected
657+
Size computeDryLayout(covariant BoxConstraints constraints) {
657658
if (!_canComputeIntrinsics) {
658659
assert(debugCannotComputeDryLayout(
659660
reason: 'Dry layout cannot be computed for CrossAxisAlignment.baseline, which requires a full layout.',

packages/flutter/lib/src/rendering/flow.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ class RenderFlow extends RenderBox
299299
}
300300

301301
@override
302-
Size computeDryLayout(BoxConstraints constraints) {
302+
@protected
303+
Size computeDryLayout(covariant BoxConstraints constraints) {
303304
return _getSize(constraints);
304305
}
305306

packages/flutter/lib/src/rendering/image.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'dart:ui' as ui show Image;
66

77
import 'package:flutter/animation.dart';
8+
import 'package:flutter/foundation.dart';
89

910
import 'box.dart';
1011
import 'object.dart';
@@ -401,7 +402,8 @@ class RenderImage extends RenderBox {
401402
bool hitTestSelf(Offset position) => true;
402403

403404
@override
404-
Size computeDryLayout(BoxConstraints constraints) {
405+
@protected
406+
Size computeDryLayout(covariant BoxConstraints constraints) {
405407
return _sizeForConstraints(constraints);
406408
}
407409

packages/flutter/lib/src/rendering/list_body.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import 'dart:math' as math;
66

7+
import 'package:flutter/foundation.dart';
8+
79
import 'box.dart';
810
import 'object.dart';
911

@@ -62,7 +64,8 @@ class RenderListBody extends RenderBox
6264
Axis get mainAxis => axisDirectionToAxis(axisDirection);
6365

6466
@override
65-
Size computeDryLayout(BoxConstraints constraints) {
67+
@protected
68+
Size computeDryLayout(covariant BoxConstraints constraints) {
6669
assert(_debugCheckConstraints(constraints));
6770
double mainAxisExtent = 0.0;
6871
RenderBox? child = firstChild;

packages/flutter/lib/src/rendering/list_wheel_viewport.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'dart:math' as math;
66

77
import 'package:flutter/animation.dart';
8+
import 'package:flutter/foundation.dart';
89
import 'package:vector_math/vector_math_64.dart' show Matrix4;
910

1011
import 'box.dart';
@@ -615,7 +616,8 @@ class RenderListWheelViewport
615616
bool get sizedByParent => true;
616617

617618
@override
618-
Size computeDryLayout(BoxConstraints constraints) {
619+
@protected
620+
Size computeDryLayout(covariant BoxConstraints constraints) {
619621
return constraints.biggest;
620622
}
621623

0 commit comments

Comments
 (0)