Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit cd125e1

Browse files
gnpricegoderbauer
andauthored
Add test for RenderProxyBoxMixin; clarify doc, resolve TODO (#117664)
* Add test for RenderProxyBoxMixin; clarify doc, resolve TODO The TODO comment suggested this mixin would no longer be needed once a Dart issue on inherited constructors was fixed: dart-lang/sdk#31543 That issue is now long since fixed, so I went to go carry out the TODO. But in doing so, I realized that the mixin's documentation was more right than the TODO comment: even with that issue fixed, there is a legitimate use case for this mixin, namely to reuse the implementation of RenderProxyBox in a class that also inherits from some other base class. Moreover, searching GitHub I found an example of a library that makes real use of that capability. So I think the right resolution is to accept that this separation is useful and delete the TODO. Then, add a test with an extremely simplified sketch of that real-world example. In case someone in the future attempts to simplify this mixin away, the test will point us at the use case that would be broken by such a change. Also remove the only in-tree use of the mixin, which was redundant; and expand the mixin's documentation to advise about that case. * Tweak formatting Co-authored-by: Michael Goderbauer <[email protected]> * Cut comments --------- Co-authored-by: Michael Goderbauer <[email protected]>
1 parent 98b3e48 commit cd125e1

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ class RenderProxyBox extends RenderBox with RenderObjectWithChildMixin<RenderBox
5353
///
5454
/// Use this mixin in situations where the proxying behavior
5555
/// of [RenderProxyBox] is desired but inheriting from [RenderProxyBox] is
56-
/// impractical (e.g. because you want to mix in other classes as well).
57-
// TODO(ianh): Remove this class once https://github.com/dart-lang/sdk/issues/31543 is fixed
56+
/// impractical (e.g. because you want to inherit from a different class).
57+
///
58+
/// If a class already inherits from [RenderProxyBox] and also uses this mixin,
59+
/// you can safely delete the use of the mixin.
5860
@optionalTypeArgs
5961
mixin RenderProxyBoxMixin<T extends RenderBox> on RenderBox, RenderObjectWithChildMixin<T> {
6062
@override
@@ -1095,7 +1097,7 @@ mixin RenderAnimatedOpacityMixin<T extends RenderObject> on RenderObjectWithChil
10951097
///
10961098
/// This is a variant of [RenderOpacity] that uses an [Animation<double>] rather
10971099
/// than a [double] to control the opacity.
1098-
class RenderAnimatedOpacity extends RenderProxyBox with RenderProxyBoxMixin, RenderAnimatedOpacityMixin<RenderBox> {
1100+
class RenderAnimatedOpacity extends RenderProxyBox with RenderAnimatedOpacityMixin<RenderBox> {
10991101
/// Creates a partially transparent render object.
11001102
///
11011103
/// The [opacity] argument must not be null.

packages/flutter/test/rendering/proxy_box_test.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,17 @@ void main() {
963963
expect(debugPaintClipOval(Clip.none), paintsExactlyCountTimes(#drawPath, 0));
964964
expect(debugPaintClipOval(Clip.none), paintsExactlyCountTimes(#drawParagraph, 0));
965965
});
966+
967+
test('RenderProxyBox behavior can be mixed in along with another base class', () {
968+
final RenderFancyProxyBox fancyProxyBox = RenderFancyProxyBox(fancy: 6);
969+
// Box has behavior from its base class:
970+
expect(fancyProxyBox.fancyMethod(), 36);
971+
// Box has behavior from RenderProxyBox:
972+
expect(
973+
fancyProxyBox.computeDryLayout(const BoxConstraints(minHeight: 8)),
974+
const Size(0, 8),
975+
);
976+
});
966977
}
967978

968979
class _TestRectClipper extends CustomClipper<Rect> {
@@ -1061,6 +1072,21 @@ class ConditionalRepaintBoundary extends RenderProxyBox {
10611072

10621073
class TestOffsetLayerA extends OffsetLayer {}
10631074

1075+
class RenderFancyBox extends RenderBox {
1076+
RenderFancyBox({required this.fancy}) : super();
1077+
1078+
late int fancy;
1079+
1080+
int fancyMethod() {
1081+
return fancy * fancy;
1082+
}
1083+
}
1084+
1085+
class RenderFancyProxyBox extends RenderFancyBox
1086+
with RenderObjectWithChildMixin<RenderBox>, RenderProxyBoxMixin<RenderBox> {
1087+
RenderFancyProxyBox({required super.fancy});
1088+
}
1089+
10641090
void expectAssertionError() {
10651091
final FlutterErrorDetails errorDetails = TestRenderingFlutterBinding.instance.takeFlutterErrorDetails()!;
10661092
final bool asserted = errorDetails.toString().contains('Failed assertion');

0 commit comments

Comments
 (0)