Replace RenderBox.compute* with RenderBox.get* and add @visibleForOverriding (#145503)
`@visibleForOverriding` + `@protected` unfortunately does not catch the case where a `compute*` method was overridden in a subtype and the overide was called in that same type's implementation. I did not add a `flutter_ignore` for this because it doesn't seem there will be false positives.
This commit is contained in:
@@ -17,6 +17,7 @@ export 'package:meta/meta.dart' show
|
||||
optionalTypeArgs,
|
||||
protected,
|
||||
required,
|
||||
visibleForOverriding,
|
||||
visibleForTesting;
|
||||
|
||||
export 'src/foundation/annotations.dart';
|
||||
|
||||
@@ -1178,11 +1178,11 @@ class _RenderCupertinoDialog extends RenderBox {
|
||||
// for buttons to just over 1 button's height to make room for the content
|
||||
// section.
|
||||
_AlertDialogSizes performRegularLayout({required BoxConstraints constraints, required ChildLayouter layoutChild}) {
|
||||
final bool hasDivider = contentSection!.getMaxIntrinsicHeight(computeMaxIntrinsicWidth(0)) > 0.0
|
||||
&& actionsSection!.getMaxIntrinsicHeight(computeMaxIntrinsicWidth(0)) > 0.0;
|
||||
final bool hasDivider = contentSection!.getMaxIntrinsicHeight(getMaxIntrinsicWidth(0)) > 0.0
|
||||
&& actionsSection!.getMaxIntrinsicHeight(getMaxIntrinsicWidth(0)) > 0.0;
|
||||
final double dividerThickness = hasDivider ? _dividerThickness : 0.0;
|
||||
|
||||
final double minActionsHeight = actionsSection!.getMinIntrinsicHeight(computeMaxIntrinsicWidth(0));
|
||||
final double minActionsHeight = actionsSection!.getMinIntrinsicHeight(getMaxIntrinsicWidth(0));
|
||||
|
||||
final Size contentSize = layoutChild(
|
||||
contentSection!,
|
||||
@@ -2017,7 +2017,7 @@ class _RenderCupertinoDialogActions extends RenderBox
|
||||
return 0.0;
|
||||
} else if (isActionSheet) {
|
||||
if (childCount == 1) {
|
||||
return firstChild!.computeMaxIntrinsicHeight(width) + dividerThickness;
|
||||
return firstChild!.getMaxIntrinsicHeight(width) + dividerThickness;
|
||||
}
|
||||
if (hasCancelButton && childCount < 4) {
|
||||
return _computeMinIntrinsicHeightWithCancel(width);
|
||||
@@ -2089,7 +2089,7 @@ class _RenderCupertinoDialogActions extends RenderBox
|
||||
return 0.0;
|
||||
} else if (isActionSheet) {
|
||||
if (childCount == 1) {
|
||||
return firstChild!.computeMaxIntrinsicHeight(width) + dividerThickness;
|
||||
return firstChild!.getMaxIntrinsicHeight(width) + dividerThickness;
|
||||
}
|
||||
return _computeMaxIntrinsicHeightStacked(width);
|
||||
} else if (childCount == 1) {
|
||||
@@ -2243,7 +2243,7 @@ class _RenderCupertinoDialogActions extends RenderBox
|
||||
|
||||
// Our height is the accumulated height of all buttons and dividers.
|
||||
return constraints.constrain(
|
||||
Size(computeMaxIntrinsicWidth(0), verticalOffset),
|
||||
Size(getMaxIntrinsicWidth(0), verticalOffset),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1757,7 +1757,7 @@ class _RenderChip extends RenderBox with SlottedContainerRenderObjectMixin<_Chip
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicHeight(double width) => computeMinIntrinsicHeight(width);
|
||||
double computeMaxIntrinsicHeight(double width) => getMinIntrinsicHeight(width);
|
||||
|
||||
@override
|
||||
double? computeDistanceToActualBaseline(TextBaseline baseline) {
|
||||
|
||||
@@ -885,8 +885,8 @@ class _RenderDropdownMenuBody extends RenderBox
|
||||
RenderBox? child = firstChild;
|
||||
|
||||
final BoxConstraints innerConstraints = BoxConstraints(
|
||||
maxWidth: width ?? computeMaxIntrinsicWidth(constraints.maxWidth),
|
||||
maxHeight: computeMaxIntrinsicHeight(constraints.maxHeight),
|
||||
maxWidth: width ?? getMaxIntrinsicWidth(constraints.maxWidth),
|
||||
maxHeight: getMaxIntrinsicHeight(constraints.maxHeight),
|
||||
);
|
||||
while (child != null) {
|
||||
if (child == firstChild) {
|
||||
@@ -927,8 +927,8 @@ class _RenderDropdownMenuBody extends RenderBox
|
||||
double? maxHeight;
|
||||
RenderBox? child = firstChild;
|
||||
final BoxConstraints innerConstraints = BoxConstraints(
|
||||
maxWidth: width ?? computeMaxIntrinsicWidth(constraints.maxWidth),
|
||||
maxHeight: computeMaxIntrinsicHeight(constraints.maxHeight),
|
||||
maxWidth: width ?? getMaxIntrinsicWidth(constraints.maxWidth),
|
||||
maxHeight: getMaxIntrinsicHeight(constraints.maxHeight),
|
||||
);
|
||||
|
||||
while (child != null) {
|
||||
|
||||
@@ -1317,7 +1317,7 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicHeight(double width) {
|
||||
return computeMinIntrinsicHeight(width);
|
||||
return getMinIntrinsicHeight(width);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -1325,7 +1325,7 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
|
||||
final RenderBox? input = this.input;
|
||||
return input == null
|
||||
? 0.0
|
||||
: _boxParentData(input).offset.dy + (input.computeDistanceToActualBaseline(baseline) ?? 0.0);
|
||||
: _boxParentData(input).offset.dy + (input.getDistanceToActualBaseline(baseline) ?? 0.0);
|
||||
}
|
||||
|
||||
// Records where the label was painted.
|
||||
|
||||
@@ -1273,7 +1273,7 @@ class _RenderListTile extends RenderBox with SlottedContainerRenderObjectMixin<_
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicHeight(double width) {
|
||||
return computeMinIntrinsicHeight(width);
|
||||
return getMinIntrinsicHeight(width);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -1177,7 +1177,7 @@ class _SelectToggleButtonRenderObject extends RenderShiftedBox {
|
||||
@override
|
||||
double? computeDistanceToActualBaseline(TextBaseline baseline) {
|
||||
// The baseline of this widget is the baseline of its child
|
||||
final BaselineOffset childOffset = BaselineOffset(child?.computeDistanceToActualBaseline(baseline));
|
||||
final BaselineOffset childOffset = BaselineOffset(child?.getDistanceToActualBaseline(baseline));
|
||||
return switch (direction) {
|
||||
Axis.horizontal => childOffset + borderSide.width,
|
||||
Axis.vertical => childOffset + leadingBorderSide.width,
|
||||
|
||||
@@ -1771,6 +1771,7 @@ abstract class RenderBox extends RenderObject {
|
||||
/// See also:
|
||||
///
|
||||
/// * [computeMinIntrinsicWidth], which has usage examples.
|
||||
@visibleForOverriding
|
||||
@protected
|
||||
double computeMaxIntrinsicWidth(double height) {
|
||||
return 0.0;
|
||||
@@ -1845,6 +1846,7 @@ abstract class RenderBox extends RenderObject {
|
||||
/// * [computeMinIntrinsicWidth], which has usage examples.
|
||||
/// * [computeMaxIntrinsicHeight], which computes the smallest height beyond
|
||||
/// which increasing the height never decreases the preferred width.
|
||||
@visibleForOverriding
|
||||
@protected
|
||||
double computeMinIntrinsicHeight(double width) {
|
||||
return 0.0;
|
||||
@@ -1922,6 +1924,7 @@ abstract class RenderBox extends RenderObject {
|
||||
/// See also:
|
||||
///
|
||||
/// * [computeMinIntrinsicWidth], which has usage examples.
|
||||
@visibleForOverriding
|
||||
@protected
|
||||
double computeMaxIntrinsicHeight(double width) {
|
||||
return 0.0;
|
||||
@@ -1995,6 +1998,7 @@ abstract class RenderBox extends RenderObject {
|
||||
/// return a valid answer. In such cases, the function should call
|
||||
/// [debugCannotComputeDryLayout] from within an assert and return a dummy
|
||||
/// value of `const Size(0, 0)`.
|
||||
@visibleForOverriding
|
||||
@protected
|
||||
Size computeDryLayout(covariant BoxConstraints constraints) {
|
||||
assert(debugCannotComputeDryLayout(
|
||||
@@ -2093,6 +2097,7 @@ abstract class RenderBox extends RenderObject {
|
||||
/// updating the widget tree, violating the "dry" contract. In such cases the
|
||||
/// [RenderBox] must call [debugCannotComputeDryLayout] in an assert, and
|
||||
/// return a dummy baseline offset value (such as `null`).
|
||||
@visibleForOverriding
|
||||
@protected
|
||||
double? computeDryBaseline(covariant BoxConstraints constraints, TextBaseline baseline) {
|
||||
assert(debugCannotComputeDryLayout(
|
||||
@@ -2405,6 +2410,7 @@ abstract class RenderBox extends RenderObject {
|
||||
/// computation, call [getDistanceToActualBaseline] on the child (not
|
||||
/// [computeDistanceToActualBaseline], the internal implementation, and not
|
||||
/// [getDistanceToBaseline], the public entry point for this API).
|
||||
@visibleForOverriding
|
||||
@protected
|
||||
double? computeDistanceToActualBaseline(TextBaseline baseline) {
|
||||
assert(_debugDoingBaseline, 'Please see the documentation for computeDistanceToActualBaseline for the required calling conventions of this method.');
|
||||
|
||||
@@ -1922,7 +1922,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicHeight(double width) => computeMaxIntrinsicHeight(width);
|
||||
double computeMinIntrinsicHeight(double width) => getMaxIntrinsicHeight(width);
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicHeight(double width) {
|
||||
|
||||
@@ -563,10 +563,8 @@ class RenderAspectRatio extends RenderProxyBox {
|
||||
|
||||
@override
|
||||
void performLayout() {
|
||||
size = computeDryLayout(constraints);
|
||||
if (child != null) {
|
||||
child!.layout(BoxConstraints.tight(size));
|
||||
}
|
||||
size = getDryLayout(constraints);
|
||||
child?.layout(BoxConstraints.tight(size));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -661,7 +659,7 @@ class RenderIntrinsicWidth extends RenderProxyBox {
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicWidth(double height) {
|
||||
return computeMaxIntrinsicWidth(height);
|
||||
return getMaxIntrinsicWidth(height);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -679,7 +677,7 @@ class RenderIntrinsicWidth extends RenderProxyBox {
|
||||
return 0.0;
|
||||
}
|
||||
if (!width.isFinite) {
|
||||
width = computeMaxIntrinsicWidth(double.infinity);
|
||||
width = getMaxIntrinsicWidth(double.infinity);
|
||||
}
|
||||
assert(width.isFinite);
|
||||
final double height = child!.getMinIntrinsicHeight(width);
|
||||
@@ -692,7 +690,7 @@ class RenderIntrinsicWidth extends RenderProxyBox {
|
||||
return 0.0;
|
||||
}
|
||||
if (!width.isFinite) {
|
||||
width = computeMaxIntrinsicWidth(double.infinity);
|
||||
width = getMaxIntrinsicWidth(double.infinity);
|
||||
}
|
||||
assert(width.isFinite);
|
||||
final double height = child!.getMaxIntrinsicHeight(width);
|
||||
@@ -802,7 +800,7 @@ class RenderIntrinsicHeight extends RenderProxyBox {
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicHeight(double width) {
|
||||
return computeMaxIntrinsicHeight(width);
|
||||
return getMaxIntrinsicHeight(width);
|
||||
}
|
||||
|
||||
Size _computeSize({required ChildLayouter layoutChild, required BoxConstraints constraints}) {
|
||||
|
||||
@@ -800,7 +800,7 @@ class RenderTable extends RenderBox {
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicHeight(double width) {
|
||||
return computeMinIntrinsicHeight(width);
|
||||
return getMinIntrinsicHeight(width);
|
||||
}
|
||||
|
||||
double? _baselineDistance;
|
||||
|
||||
@@ -396,7 +396,7 @@ class RenderWrap extends RenderBox
|
||||
}
|
||||
return width;
|
||||
case Axis.vertical:
|
||||
return computeDryLayout(BoxConstraints(maxHeight: height)).width;
|
||||
return getDryLayout(BoxConstraints(maxHeight: height)).width;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -412,7 +412,7 @@ class RenderWrap extends RenderBox
|
||||
}
|
||||
return width;
|
||||
case Axis.vertical:
|
||||
return computeDryLayout(BoxConstraints(maxHeight: height)).width;
|
||||
return getDryLayout(BoxConstraints(maxHeight: height)).width;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,7 +420,7 @@ class RenderWrap extends RenderBox
|
||||
double computeMinIntrinsicHeight(double width) {
|
||||
switch (direction) {
|
||||
case Axis.horizontal:
|
||||
return computeDryLayout(BoxConstraints(maxWidth: width)).height;
|
||||
return getDryLayout(BoxConstraints(maxWidth: width)).height;
|
||||
case Axis.vertical:
|
||||
double height = 0.0;
|
||||
RenderBox? child = firstChild;
|
||||
@@ -436,7 +436,7 @@ class RenderWrap extends RenderBox
|
||||
double computeMaxIntrinsicHeight(double width) {
|
||||
switch (direction) {
|
||||
case Axis.horizontal:
|
||||
return computeDryLayout(BoxConstraints(maxWidth: width)).height;
|
||||
return getDryLayout(BoxConstraints(maxWidth: width)).height;
|
||||
case Axis.vertical:
|
||||
double height = 0.0;
|
||||
RenderBox? child = firstChild;
|
||||
|
||||
@@ -353,22 +353,22 @@ class _RenderScaledInlineWidget extends RenderBox with RenderObjectWithChildMixi
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicHeight(double width) {
|
||||
return (child?.computeMaxIntrinsicHeight(width / scale) ?? 0.0) * scale;
|
||||
return (child?.getMaxIntrinsicHeight(width / scale) ?? 0.0) * scale;
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicWidth(double height) {
|
||||
return (child?.computeMaxIntrinsicWidth(height / scale) ?? 0.0) * scale;
|
||||
return (child?.getMaxIntrinsicWidth(height / scale) ?? 0.0) * scale;
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicHeight(double width) {
|
||||
return (child?.computeMinIntrinsicHeight(width / scale) ?? 0.0) * scale;
|
||||
return (child?.getMinIntrinsicHeight(width / scale) ?? 0.0) * scale;
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicWidth(double height) {
|
||||
return (child?.computeMinIntrinsicWidth(height / scale) ?? 0.0) * scale;
|
||||
return (child?.getMinIntrinsicWidth(height / scale) ?? 0.0) * scale;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -382,7 +382,7 @@ class _RenderScaledInlineWidget extends RenderBox with RenderObjectWithChildMixi
|
||||
@override
|
||||
Size computeDryLayout(BoxConstraints constraints) {
|
||||
assert(!constraints.hasBoundedHeight);
|
||||
final Size unscaledSize = child?.computeDryLayout(BoxConstraints(maxWidth: constraints.maxWidth / scale)) ?? Size.zero;
|
||||
final Size unscaledSize = child?.getDryLayout(BoxConstraints(maxWidth: constraints.maxWidth / scale)) ?? Size.zero;
|
||||
return constraints.constrain(unscaledSize * scale);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user