fix debug paint crash when axis direction inverted (#37033)
This commit is contained in:
parent
771c843f56
commit
7a236aed12
@ -1425,6 +1425,10 @@ abstract class RenderSliver extends RenderObject {
|
|||||||
/// This means that the dimensions may be negative.
|
/// This means that the dimensions may be negative.
|
||||||
///
|
///
|
||||||
/// This is only valid after [layout] has completed.
|
/// This is only valid after [layout] has completed.
|
||||||
|
///
|
||||||
|
/// See also:
|
||||||
|
///
|
||||||
|
/// * [getAbsoluteSize], which returns absolute size.
|
||||||
@protected
|
@protected
|
||||||
Size getAbsoluteSizeRelativeToOrigin() {
|
Size getAbsoluteSizeRelativeToOrigin() {
|
||||||
assert(geometry != null);
|
assert(geometry != null);
|
||||||
@ -1442,6 +1446,30 @@ abstract class RenderSliver extends RenderObject {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This returns the absolute [Size] of the sliver.
|
||||||
|
///
|
||||||
|
/// The dimensions are always positive and calling this is only valid after
|
||||||
|
/// [layout] has completed.
|
||||||
|
///
|
||||||
|
/// See also:
|
||||||
|
///
|
||||||
|
/// * [getAbsoluteSizeRelativeToOrigin], which returns the size relative to
|
||||||
|
/// the leading edge of the sliver.
|
||||||
|
@protected
|
||||||
|
Size getAbsoluteSize() {
|
||||||
|
assert(geometry != null);
|
||||||
|
assert(!debugNeedsLayout);
|
||||||
|
switch (constraints.axisDirection) {
|
||||||
|
case AxisDirection.up:
|
||||||
|
case AxisDirection.down:
|
||||||
|
return Size(constraints.crossAxisExtent, geometry.paintExtent);
|
||||||
|
case AxisDirection.right:
|
||||||
|
case AxisDirection.left:
|
||||||
|
return Size(geometry.paintExtent, constraints.crossAxisExtent);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
void _debugDrawArrow(Canvas canvas, Paint paint, Offset p0, Offset p1, GrowthDirection direction) {
|
void _debugDrawArrow(Canvas canvas, Paint paint, Offset p0, Offset p1, GrowthDirection direction) {
|
||||||
assert(() {
|
assert(() {
|
||||||
if (p0 == p1)
|
if (p0 == p1)
|
||||||
|
@ -328,12 +328,12 @@ class RenderSliverPadding extends RenderSliver with RenderObjectWithChildMixin<R
|
|||||||
super.debugPaint(context, offset);
|
super.debugPaint(context, offset);
|
||||||
assert(() {
|
assert(() {
|
||||||
if (debugPaintSizeEnabled) {
|
if (debugPaintSizeEnabled) {
|
||||||
final Size parentSize = getAbsoluteSizeRelativeToOrigin();
|
final Size parentSize = getAbsoluteSize();
|
||||||
final Rect outerRect = offset & parentSize;
|
final Rect outerRect = offset & parentSize;
|
||||||
Size childSize;
|
Size childSize;
|
||||||
Rect innerRect;
|
Rect innerRect;
|
||||||
if (child != null) {
|
if (child != null) {
|
||||||
childSize = child.getAbsoluteSizeRelativeToOrigin();
|
childSize = child.getAbsoluteSize();
|
||||||
final SliverPhysicalParentData childParentData = child.parentData;
|
final SliverPhysicalParentData childParentData = child.parentData;
|
||||||
innerRect = (offset + childParentData.paintOffset) & childSize;
|
innerRect = (offset + childParentData.paintOffset) & childSize;
|
||||||
assert(innerRect.top >= outerRect.top);
|
assert(innerRect.top >= outerRect.top);
|
||||||
|
@ -124,4 +124,70 @@ void main() {
|
|||||||
expect(b.debugPaint, isNot(paints..rect(color: const Color(0x90909090))));
|
expect(b.debugPaint, isNot(paints..rect(color: const Color(0x90909090))));
|
||||||
debugPaintSizeEnabled = false;
|
debugPaintSizeEnabled = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('debugPaintPadding from render objects with inverted direction vertical', () {
|
||||||
|
debugPaintSizeEnabled = true;
|
||||||
|
RenderSliver s;
|
||||||
|
final RenderViewport root = RenderViewport(
|
||||||
|
axisDirection: AxisDirection.up,
|
||||||
|
crossAxisDirection: AxisDirection.right,
|
||||||
|
offset: ViewportOffset.zero(),
|
||||||
|
children: <RenderSliver>[
|
||||||
|
s = RenderSliverPadding(
|
||||||
|
padding: const EdgeInsets.all(10.0),
|
||||||
|
child: RenderSliverToBoxAdapter(
|
||||||
|
child: RenderPadding(
|
||||||
|
padding: const EdgeInsets.all(10.0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
layout(root);
|
||||||
|
dynamic error;
|
||||||
|
try {
|
||||||
|
s.debugPaint(
|
||||||
|
PaintingContext(
|
||||||
|
ContainerLayer(), const Rect.fromLTRB(0.0, 0.0, 800.0, 600.0)),
|
||||||
|
const Offset(0.0, 500)
|
||||||
|
);
|
||||||
|
} catch(e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
expect(error, isNull);
|
||||||
|
debugPaintSizeEnabled = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('debugPaintPadding from render objects with inverted direction horizontal', () {
|
||||||
|
debugPaintSizeEnabled = true;
|
||||||
|
RenderSliver s;
|
||||||
|
final RenderViewport root = RenderViewport(
|
||||||
|
axisDirection: AxisDirection.left,
|
||||||
|
crossAxisDirection: AxisDirection.down,
|
||||||
|
offset: ViewportOffset.zero(),
|
||||||
|
children: <RenderSliver>[
|
||||||
|
s = RenderSliverPadding(
|
||||||
|
padding: const EdgeInsets.all(10.0),
|
||||||
|
child: RenderSliverToBoxAdapter(
|
||||||
|
child: RenderPadding(
|
||||||
|
padding: const EdgeInsets.all(10.0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
layout(root);
|
||||||
|
dynamic error;
|
||||||
|
try {
|
||||||
|
s.debugPaint(
|
||||||
|
PaintingContext(
|
||||||
|
ContainerLayer(), const Rect.fromLTRB(0.0, 0.0, 800.0, 600.0)),
|
||||||
|
const Offset(0.0, 500)
|
||||||
|
);
|
||||||
|
} catch(e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
expect(error, isNull);
|
||||||
|
debugPaintSizeEnabled = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user