Skip to content

Commit 30c2d77

Browse files
authored
Remove Deprecated RenderUnconstrainedBox (#111711)
1 parent 888b141 commit 30c2d77

File tree

2 files changed

+21
-100
lines changed

2 files changed

+21
-100
lines changed

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

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -879,91 +879,6 @@ class RenderConstraintsTransformBox extends RenderAligningShiftedBox with DebugO
879879
}
880880
}
881881

882-
/// Renders a box, imposing no constraints on its child, allowing the child to
883-
/// render at its "natural" size.
884-
///
885-
/// The class is deprecated, use [RenderConstraintsTransformBox] instead.
886-
///
887-
/// This allows a child to render at the size it would render if it were alone
888-
/// on an infinite canvas with no constraints. This box will then attempt to
889-
/// adopt the same size, within the limits of its own constraints. If it ends
890-
/// up with a different size, it will align the child based on [alignment].
891-
/// If the box cannot expand enough to accommodate the entire child, the
892-
/// child will be clipped.
893-
///
894-
/// In debug mode, if the child overflows the box, a warning will be printed on
895-
/// the console, and black and yellow striped areas will appear where the
896-
/// overflow occurs.
897-
///
898-
/// See also:
899-
///
900-
/// * [RenderConstrainedBox], which renders a box which imposes constraints
901-
/// on its child.
902-
/// * [RenderConstrainedOverflowBox], which renders a box that imposes different
903-
/// constraints on its child than it gets from its parent, possibly allowing
904-
/// the child to overflow the parent.
905-
/// * [RenderSizedOverflowBox], a render object that is a specific size but
906-
/// passes its original constraints through to its child, which it allows to
907-
/// overflow.
908-
///
909-
@Deprecated(
910-
'Use RenderConstraintsTransformBox instead. '
911-
'This feature was deprecated after v2.1.0-11.0.pre.',
912-
)
913-
class RenderUnconstrainedBox extends RenderConstraintsTransformBox {
914-
/// Create a render object that sizes itself to the child but does not
915-
/// pass the [constraints] down to that child.
916-
///
917-
/// The [alignment] and [clipBehavior] must not be null.
918-
@Deprecated(
919-
'Use RenderConstraintsTransformBox instead. '
920-
'This feature was deprecated after v2.1.0-11.0.pre.',
921-
)
922-
RenderUnconstrainedBox({
923-
required super.alignment,
924-
required super.textDirection,
925-
Axis? constrainedAxis,
926-
super.child,
927-
super.clipBehavior,
928-
}) : assert(alignment != null),
929-
assert(clipBehavior != null),
930-
_constrainedAxis = constrainedAxis,
931-
super(
932-
constraintsTransform: _convertAxis(constrainedAxis),
933-
);
934-
935-
/// The axis to retain constraints on, if any.
936-
///
937-
/// If not set, or set to null (the default), neither axis will retain its
938-
/// constraints. If set to [Axis.vertical], then vertical constraints will
939-
/// be retained, and if set to [Axis.horizontal], then horizontal constraints
940-
/// will be retained.
941-
Axis? get constrainedAxis => _constrainedAxis;
942-
Axis? _constrainedAxis;
943-
set constrainedAxis(Axis? value) {
944-
if (_constrainedAxis == value) {
945-
return;
946-
}
947-
_constrainedAxis = value;
948-
constraintsTransform = _convertAxis(constrainedAxis);
949-
}
950-
951-
static BoxConstraints _unconstrained(BoxConstraints constraints) => const BoxConstraints();
952-
static BoxConstraints _widthConstrained(BoxConstraints constraints) => constraints.widthConstraints();
953-
static BoxConstraints _heightConstrained(BoxConstraints constraints) => constraints.heightConstraints();
954-
static BoxConstraintsTransform _convertAxis(Axis? constrainedAxis) {
955-
if (constrainedAxis == null) {
956-
return _unconstrained;
957-
}
958-
switch (constrainedAxis) {
959-
case Axis.horizontal:
960-
return _widthConstrained;
961-
case Axis.vertical:
962-
return _heightConstrained;
963-
}
964-
}
965-
}
966-
967882
/// A render object that is a specific size but passes its original constraints
968883
/// through to its child, which it allows to overflow.
969884
///

packages/flutter/test/rendering/box_test.dart

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ void main() {
336336
});
337337

338338
test('UnconstrainedBox expands to fit children', () {
339-
final RenderUnconstrainedBox unconstrained = RenderUnconstrainedBox(
340-
constrainedAxis: Axis.horizontal, // This is reset to null below.
339+
final RenderConstraintsTransformBox unconstrained = RenderConstraintsTransformBox(
340+
constraintsTransform: ConstraintsTransformBox.widthUnconstrained,
341341
textDirection: TextDirection.ltr,
342342
child: RenderConstrainedBox(
343343
additionalConstraints: const BoxConstraints.tightFor(width: 200.0, height: 200.0),
@@ -354,15 +354,16 @@ void main() {
354354
),
355355
);
356356
// Check that we can update the constrained axis to null.
357-
unconstrained.constrainedAxis = null;
357+
unconstrained.constraintsTransform = ConstraintsTransformBox.unconstrained;
358358
TestRenderingFlutterBinding.instance.reassembleApplication();
359359

360360
expect(unconstrained.size.width, equals(200.0), reason: 'unconstrained width');
361361
expect(unconstrained.size.height, equals(200.0), reason: 'unconstrained height');
362362
});
363363

364364
test('UnconstrainedBox handles vertical overflow', () {
365-
final RenderUnconstrainedBox unconstrained = RenderUnconstrainedBox(
365+
final RenderConstraintsTransformBox unconstrained = RenderConstraintsTransformBox(
366+
constraintsTransform: ConstraintsTransformBox.unconstrained,
366367
textDirection: TextDirection.ltr,
367368
child: RenderConstrainedBox(
368369
additionalConstraints: const BoxConstraints.tightFor(height: 200.0),
@@ -378,7 +379,8 @@ void main() {
378379
});
379380

380381
test('UnconstrainedBox handles horizontal overflow', () {
381-
final RenderUnconstrainedBox unconstrained = RenderUnconstrainedBox(
382+
final RenderConstraintsTransformBox unconstrained = RenderConstraintsTransformBox(
383+
constraintsTransform: ConstraintsTransformBox.unconstrained,
382384
textDirection: TextDirection.ltr,
383385
child: RenderConstrainedBox(
384386
additionalConstraints: const BoxConstraints.tightFor(width: 200.0),
@@ -508,7 +510,8 @@ void main() {
508510
});
509511

510512
test ('getMinIntrinsicWidth error handling', () {
511-
final RenderUnconstrainedBox unconstrained = RenderUnconstrainedBox(
513+
final RenderConstraintsTransformBox unconstrained = RenderConstraintsTransformBox(
514+
constraintsTransform: ConstraintsTransformBox.unconstrained,
512515
textDirection: TextDirection.ltr,
513516
child: RenderConstrainedBox(
514517
additionalConstraints: const BoxConstraints.tightFor(width: 200.0),
@@ -632,7 +635,8 @@ void main() {
632635
});
633636

634637
test('UnconstrainedBox.toStringDeep returns useful information', () {
635-
final RenderUnconstrainedBox unconstrained = RenderUnconstrainedBox(
638+
final RenderConstraintsTransformBox unconstrained = RenderConstraintsTransformBox(
639+
constraintsTransform: ConstraintsTransformBox.unconstrained,
636640
textDirection: TextDirection.ltr,
637641
alignment: Alignment.center,
638642
);
@@ -642,7 +646,7 @@ void main() {
642646
expect(
643647
unconstrained.toStringDeep(minLevel: DiagnosticLevel.info),
644648
equalsIgnoringHashCodes(
645-
'RenderUnconstrainedBox#00000 NEEDS-LAYOUT NEEDS-PAINT DETACHED\n'
649+
'RenderConstraintsTransformBox#00000 NEEDS-LAYOUT NEEDS-PAINT DETACHED\n'
646650
' parentData: MISSING\n'
647651
' constraints: MISSING\n'
648652
' size: MISSING\n'
@@ -655,8 +659,8 @@ void main() {
655659
test('UnconstrainedBox honors constrainedAxis=Axis.horizontal', () {
656660
final RenderConstrainedBox flexible =
657661
RenderConstrainedBox(additionalConstraints: const BoxConstraints.expand(height: 200.0));
658-
final RenderUnconstrainedBox unconstrained = RenderUnconstrainedBox(
659-
constrainedAxis: Axis.horizontal,
662+
final RenderConstraintsTransformBox unconstrained = RenderConstraintsTransformBox(
663+
constraintsTransform: ConstraintsTransformBox.heightUnconstrained,
660664
textDirection: TextDirection.ltr,
661665
child: RenderFlex(
662666
textDirection: TextDirection.ltr,
@@ -678,8 +682,8 @@ void main() {
678682
test('UnconstrainedBox honors constrainedAxis=Axis.vertical', () {
679683
final RenderConstrainedBox flexible =
680684
RenderConstrainedBox(additionalConstraints: const BoxConstraints.expand(width: 200.0));
681-
final RenderUnconstrainedBox unconstrained = RenderUnconstrainedBox(
682-
constrainedAxis: Axis.vertical,
685+
final RenderConstraintsTransformBox unconstrained = RenderConstraintsTransformBox(
686+
constraintsTransform: ConstraintsTransformBox.widthUnconstrained,
683687
textDirection: TextDirection.ltr,
684688
child: RenderFlex(
685689
direction: Axis.vertical,
@@ -710,21 +714,23 @@ void main() {
710714
}
711715

712716
for (final Clip? clip in <Clip?>[null, ...Clip.values]) {
713-
final RenderUnconstrainedBox box;
717+
final RenderConstraintsTransformBox box;
714718
switch (clip) {
715719
case Clip.none:
716720
case Clip.hardEdge:
717721
case Clip.antiAlias:
718722
case Clip.antiAliasWithSaveLayer:
719-
box = RenderUnconstrainedBox(
723+
box = RenderConstraintsTransformBox(
724+
constraintsTransform: ConstraintsTransformBox.unconstrained,
720725
alignment: Alignment.center,
721726
textDirection: TextDirection.ltr,
722727
child: box200x200,
723728
clipBehavior: clip!,
724729
);
725730
break;
726731
case null:
727-
box = RenderUnconstrainedBox(
732+
box = RenderConstraintsTransformBox(
733+
constraintsTransform: ConstraintsTransformBox.unconstrained,
728734
alignment: Alignment.center,
729735
textDirection: TextDirection.ltr,
730736
child: box200x200,

0 commit comments

Comments
 (0)