Unverified Commit ea3d4dbd authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Reland "ConstraintsTransformBox (#77994)" reverted in (#78661) (#78673)

parent 02402392
......@@ -85,7 +85,8 @@ class _OverflowRegionData {
///
/// See also:
///
/// * [RenderUnconstrainedBox] and [RenderFlex] for examples of classes that use this indicator mixin.
/// * [RenderConstraintsTransformBox], [RenderUnconstrainedBox] and
/// [RenderFlex], for examples of classes that use this indicator mixin.
mixin DebugOverflowIndicatorMixin on RenderObject {
static const Color _black = Color(0xBF000000);
static const Color _yellow = Color(0xBFFFFF00);
......
This diff is collapsed.
......@@ -378,6 +378,71 @@ void main() {
expect(unconstrained.getMaxIntrinsicWidth(100.0), equals(200.0));
});
group('ConstraintsTransfromBox', () {
FlutterErrorDetails? firstErrorDetails;
void exhaustErrors() {
FlutterErrorDetails? next;
do {
next = renderer.takeFlutterErrorDetails();
firstErrorDetails ??= next;
} while (next != null);
}
tearDown(() {
firstErrorDetails = null;
RenderObject.debugCheckingIntrinsics = false;
});
test('throws if the resulting constraints are not normalized', () {
final RenderConstrainedBox child = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(height: 0));
final RenderConstraintsTransformBox box = RenderConstraintsTransformBox(
alignment: Alignment.center,
textDirection: TextDirection.ltr,
constraintsTransform: (BoxConstraints constraints) => const BoxConstraints(maxHeight: -1, minHeight: 200),
child: child,
);
layout(box, constraints: const BoxConstraints(), onErrors: exhaustErrors);
expect(firstErrorDetails?.toString(), contains('is not normalized'));
});
test('overflow is reported when insufficient size is given', () {
final RenderConstrainedBox child = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: double.maxFinite));
final RenderConstraintsTransformBox box = RenderConstraintsTransformBox(
alignment: Alignment.center,
textDirection: TextDirection.ltr,
constraintsTransform: (BoxConstraints constraints) => constraints.copyWith(maxWidth: double.infinity),
child: child,
);
layout(box, constraints: const BoxConstraints(), phase: EnginePhase.composite, onErrors: expectOverflowedErrors);
});
test('handles flow layout', () {
final RenderParagraph child = RenderParagraph(
TextSpan(text: 'a' * 100),
textDirection: TextDirection.ltr,
);
final RenderConstraintsTransformBox box = RenderConstraintsTransformBox(
alignment: Alignment.center,
textDirection: TextDirection.ltr,
constraintsTransform: (BoxConstraints constraints) => constraints.copyWith(maxWidth: double.infinity),
child: child,
);
// With a width of 30, the RenderParagraph would have wrapped, but the
// RenderConstraintsTransformBox allows the paragraph to expand regardless
// of the width constraint:
// unconstrainedHeight * numberOfLines = constrainedHeight.
final double constrainedHeight = child.getMinIntrinsicHeight(30);
final double unconstrainedHeight = box.getMinIntrinsicHeight(30);
// At least 2 lines.
expect(constrainedHeight, greaterThanOrEqualTo(2 * unconstrainedHeight));
});
});
test ('getMinIntrinsicWidth error handling', () {
final RenderUnconstrainedBox unconstrained = RenderUnconstrainedBox(
textDirection: TextDirection.ltr,
......
......@@ -36,7 +36,7 @@ void main() {
final dynamic exception = tester.takeException();
expect(exception, isFlutterError);
expect(exception.diagnostics.first.level, DiagnosticLevel.summary);
expect(exception.diagnostics.first.toString(), startsWith('A RenderUnconstrainedBox overflowed by '));
expect(exception.diagnostics.first.toString(), startsWith('A RenderConstraintsTransformBox overflowed by '));
expect(find.byType(UnconstrainedBox), paints..rect());
await tester.pumpWidget(
......
......@@ -323,6 +323,7 @@ void main() {
const UnconstrainedBox(constrainedAxis: Axis.vertical,).toString(),
equals('UnconstrainedBox(alignment: Alignment.center, constrainedAxis: vertical)'),
);
expect(
const UnconstrainedBox(constrainedAxis: Axis.horizontal, textDirection: TextDirection.rtl, alignment: Alignment.topRight).toString(),
equals('UnconstrainedBox(alignment: Alignment.topRight, constrainedAxis: horizontal, textDirection: rtl)'),
......@@ -331,13 +332,32 @@ void main() {
testWidgets('UnconstrainedBox can set and update clipBehavior', (WidgetTester tester) async {
await tester.pumpWidget(const UnconstrainedBox());
final RenderUnconstrainedBox renderObject = tester.allRenderObjects.whereType<RenderUnconstrainedBox>().first;
final RenderConstraintsTransformBox renderObject = tester.allRenderObjects.whereType<RenderConstraintsTransformBox>().first;
expect(renderObject.clipBehavior, equals(Clip.none));
await tester.pumpWidget(const UnconstrainedBox(clipBehavior: Clip.antiAlias));
expect(renderObject.clipBehavior, equals(Clip.antiAlias));
});
group('ConstraintsTransformBox', () {
test('toString', () {
expect(
const ConstraintsTransformBox(
constraintsTransform: ConstraintsTransformBox.unconstrained,
).toString(),
equals('ConstraintsTransformBox(alignment: Alignment.center, constraints transform: unconstrained)'),
);
expect(
const ConstraintsTransformBox(
textDirection: TextDirection.rtl,
alignment: Alignment.topRight,
constraintsTransform: ConstraintsTransformBox.widthUnconstrained,
).toString(),
equals('ConstraintsTransformBox(alignment: Alignment.topRight, textDirection: rtl, constraints transform: width constraints removed)'),
);
});
});
group('ColoredBox', () {
late _MockCanvas mockCanvas;
late _MockPaintingContext mockContext;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment