Allow Clip.none as a valid clipBehavior (#95593)
This commit is contained in:
@@ -1429,13 +1429,13 @@ class RenderClipRect extends _RenderCustomClip<Rect> {
|
||||
/// If [clipper] is null, the clip will match the layout size and position of
|
||||
/// the child.
|
||||
///
|
||||
/// The [clipBehavior] must not be null or [Clip.none].
|
||||
/// The [clipBehavior] must not be null. If [clipBehavior] is
|
||||
/// [Clip.none], no clipping will be applied.
|
||||
RenderClipRect({
|
||||
RenderBox? child,
|
||||
CustomClipper<Rect>? clipper,
|
||||
Clip clipBehavior = Clip.antiAlias,
|
||||
}) : assert(clipBehavior != null),
|
||||
assert(clipBehavior != Clip.none),
|
||||
super(child: child, clipper: clipper, clipBehavior: clipBehavior);
|
||||
|
||||
@override
|
||||
@@ -1455,15 +1455,20 @@ class RenderClipRect extends _RenderCustomClip<Rect> {
|
||||
@override
|
||||
void paint(PaintingContext context, Offset offset) {
|
||||
if (child != null) {
|
||||
_updateClip();
|
||||
layer = context.pushClipRect(
|
||||
needsCompositing,
|
||||
offset,
|
||||
_clip!,
|
||||
super.paint,
|
||||
clipBehavior: clipBehavior,
|
||||
oldLayer: layer as ClipRectLayer?,
|
||||
);
|
||||
if (clipBehavior != Clip.none) {
|
||||
_updateClip();
|
||||
layer = context.pushClipRect(
|
||||
needsCompositing,
|
||||
offset,
|
||||
_clip!,
|
||||
super.paint,
|
||||
clipBehavior: clipBehavior,
|
||||
oldLayer: layer as ClipRectLayer?,
|
||||
);
|
||||
} else {
|
||||
context.paintChild(child!, offset);
|
||||
layer = null;
|
||||
}
|
||||
} else {
|
||||
layer = null;
|
||||
}
|
||||
@@ -1495,14 +1500,14 @@ class RenderClipRRect extends _RenderCustomClip<RRect> {
|
||||
///
|
||||
/// If [clipper] is non-null, then [borderRadius] is ignored.
|
||||
///
|
||||
/// The [clipBehavior] argument must not be null or [Clip.none].
|
||||
/// The [clipBehavior] argument must not be null. If [clipBehavior] is
|
||||
/// [Clip.none], no clipping will be applied.
|
||||
RenderClipRRect({
|
||||
RenderBox? child,
|
||||
BorderRadius borderRadius = BorderRadius.zero,
|
||||
CustomClipper<RRect>? clipper,
|
||||
Clip clipBehavior = Clip.antiAlias,
|
||||
}) : assert(clipBehavior != null),
|
||||
assert(clipBehavior != Clip.none),
|
||||
_borderRadius = borderRadius,
|
||||
super(child: child, clipper: clipper, clipBehavior: clipBehavior) {
|
||||
assert(_borderRadius != null || clipper != null);
|
||||
@@ -1541,14 +1546,21 @@ class RenderClipRRect extends _RenderCustomClip<RRect> {
|
||||
@override
|
||||
void paint(PaintingContext context, Offset offset) {
|
||||
if (child != null) {
|
||||
_updateClip();
|
||||
layer = context.pushClipRRect(
|
||||
needsCompositing,
|
||||
offset,
|
||||
_clip!.outerRect,
|
||||
_clip!,
|
||||
super.paint, clipBehavior: clipBehavior, oldLayer: layer as ClipRRectLayer?,
|
||||
);
|
||||
if (clipBehavior != Clip.none) {
|
||||
_updateClip();
|
||||
layer = context.pushClipRRect(
|
||||
needsCompositing,
|
||||
offset,
|
||||
_clip!.outerRect,
|
||||
_clip!,
|
||||
super.paint,
|
||||
clipBehavior: clipBehavior,
|
||||
oldLayer: layer as ClipRRectLayer?,
|
||||
);
|
||||
} else {
|
||||
context.paintChild(child!, offset);
|
||||
layer = null;
|
||||
}
|
||||
} else {
|
||||
layer = null;
|
||||
}
|
||||
@@ -1578,13 +1590,13 @@ class RenderClipOval extends _RenderCustomClip<Rect> {
|
||||
/// If [clipper] is null, the oval will be inscribed into the layout size and
|
||||
/// position of the child.
|
||||
///
|
||||
/// The [clipBehavior] argument must not be null or [Clip.none].
|
||||
/// The [clipBehavior] argument must not be null. If [clipBehavior] is
|
||||
/// [Clip.none], no clipping will be applied.
|
||||
RenderClipOval({
|
||||
RenderBox? child,
|
||||
CustomClipper<Rect>? clipper,
|
||||
Clip clipBehavior = Clip.antiAlias,
|
||||
}) : assert(clipBehavior != null),
|
||||
assert(clipBehavior != Clip.none),
|
||||
super(child: child, clipper: clipper, clipBehavior: clipBehavior);
|
||||
|
||||
Rect? _cachedRect;
|
||||
@@ -1620,16 +1632,21 @@ class RenderClipOval extends _RenderCustomClip<Rect> {
|
||||
@override
|
||||
void paint(PaintingContext context, Offset offset) {
|
||||
if (child != null) {
|
||||
_updateClip();
|
||||
layer = context.pushClipPath(
|
||||
needsCompositing,
|
||||
offset,
|
||||
_clip!,
|
||||
_getClipPath(_clip!),
|
||||
super.paint,
|
||||
clipBehavior: clipBehavior,
|
||||
oldLayer: layer as ClipPathLayer?,
|
||||
);
|
||||
if (clipBehavior != Clip.none) {
|
||||
_updateClip();
|
||||
layer = context.pushClipPath(
|
||||
needsCompositing,
|
||||
offset,
|
||||
_clip!,
|
||||
_getClipPath(_clip!),
|
||||
super.paint,
|
||||
clipBehavior: clipBehavior,
|
||||
oldLayer: layer as ClipPathLayer?,
|
||||
);
|
||||
} else {
|
||||
context.paintChild(child!, offset);
|
||||
layer = null;
|
||||
}
|
||||
} else {
|
||||
layer = null;
|
||||
}
|
||||
@@ -1667,13 +1684,13 @@ class RenderClipPath extends _RenderCustomClip<Path> {
|
||||
/// consider using a [RenderClipRect], which can achieve the same effect more
|
||||
/// efficiently.
|
||||
///
|
||||
/// The [clipBehavior] argument must not be null or [Clip.none].
|
||||
/// The [clipBehavior] argument must not be null. If [clipBehavior] is
|
||||
/// [Clip.none], no clipping will be applied.
|
||||
RenderClipPath({
|
||||
RenderBox? child,
|
||||
CustomClipper<Path>? clipper,
|
||||
Clip clipBehavior = Clip.antiAlias,
|
||||
}) : assert(clipBehavior != null),
|
||||
assert(clipBehavior != Clip.none),
|
||||
super(child: child, clipper: clipper, clipBehavior: clipBehavior);
|
||||
|
||||
@override
|
||||
@@ -1693,16 +1710,21 @@ class RenderClipPath extends _RenderCustomClip<Path> {
|
||||
@override
|
||||
void paint(PaintingContext context, Offset offset) {
|
||||
if (child != null) {
|
||||
_updateClip();
|
||||
layer = context.pushClipPath(
|
||||
needsCompositing,
|
||||
offset,
|
||||
Offset.zero & size,
|
||||
_clip!,
|
||||
super.paint,
|
||||
clipBehavior: clipBehavior,
|
||||
oldLayer: layer as ClipPathLayer?,
|
||||
);
|
||||
if (clipBehavior != Clip.none) {
|
||||
_updateClip();
|
||||
layer = context.pushClipPath(
|
||||
needsCompositing,
|
||||
offset,
|
||||
Offset.zero & size,
|
||||
_clip!,
|
||||
super.paint,
|
||||
clipBehavior: clipBehavior,
|
||||
oldLayer: layer as ClipPathLayer?,
|
||||
);
|
||||
} else {
|
||||
context.paintChild(child!, offset);
|
||||
layer = null;
|
||||
}
|
||||
} else {
|
||||
layer = null;
|
||||
}
|
||||
|
||||
@@ -662,10 +662,15 @@ class ClipRect extends SingleChildRenderObjectWidget {
|
||||
/// If [clipper] is null, the clip will match the layout size and position of
|
||||
/// the child.
|
||||
///
|
||||
/// The [clipBehavior] argument must not be null or [Clip.none].
|
||||
const ClipRect({ Key? key, this.clipper, this.clipBehavior = Clip.hardEdge, Widget? child })
|
||||
: assert(clipBehavior != null),
|
||||
super(key: key, child: child);
|
||||
/// The [clipBehavior] argument must not be null. If [clipBehavior] is
|
||||
/// [Clip.none], no clipping will be applied.
|
||||
const ClipRect({
|
||||
Key? key,
|
||||
this.clipper,
|
||||
this.clipBehavior = Clip.hardEdge,
|
||||
Widget? child,
|
||||
}) : assert(clipBehavior != null),
|
||||
super(key: key, child: child);
|
||||
|
||||
/// If non-null, determines which clip to use.
|
||||
final CustomClipper<Rect>? clipper;
|
||||
@@ -677,13 +682,11 @@ class ClipRect extends SingleChildRenderObjectWidget {
|
||||
|
||||
@override
|
||||
RenderClipRect createRenderObject(BuildContext context) {
|
||||
assert(clipBehavior != Clip.none);
|
||||
return RenderClipRect(clipper: clipper, clipBehavior: clipBehavior);
|
||||
}
|
||||
|
||||
@override
|
||||
void updateRenderObject(BuildContext context, RenderClipRect renderObject) {
|
||||
assert(clipBehavior != Clip.none);
|
||||
renderObject
|
||||
..clipper = clipper
|
||||
..clipBehavior = clipBehavior;
|
||||
@@ -723,7 +726,8 @@ class ClipRRect extends SingleChildRenderObjectWidget {
|
||||
///
|
||||
/// If [clipper] is non-null, then [borderRadius] is ignored.
|
||||
///
|
||||
/// The [clipBehavior] argument must not be null or [Clip.none].
|
||||
/// The [clipBehavior] argument must not be null. If [clipBehavior] is
|
||||
/// [Clip.none], no clipping will be applied.
|
||||
const ClipRRect({
|
||||
Key? key,
|
||||
this.borderRadius = BorderRadius.zero,
|
||||
@@ -752,13 +756,15 @@ class ClipRRect extends SingleChildRenderObjectWidget {
|
||||
|
||||
@override
|
||||
RenderClipRRect createRenderObject(BuildContext context) {
|
||||
assert(clipBehavior != Clip.none);
|
||||
return RenderClipRRect(borderRadius: borderRadius!, clipper: clipper, clipBehavior: clipBehavior);
|
||||
return RenderClipRRect(
|
||||
borderRadius: borderRadius!,
|
||||
clipper: clipper,
|
||||
clipBehavior: clipBehavior,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void updateRenderObject(BuildContext context, RenderClipRRect renderObject) {
|
||||
assert(clipBehavior != Clip.none);
|
||||
renderObject
|
||||
..borderRadius = borderRadius!
|
||||
..clipBehavior = clipBehavior
|
||||
@@ -793,10 +799,15 @@ class ClipOval extends SingleChildRenderObjectWidget {
|
||||
/// If [clipper] is null, the oval will be inscribed into the layout size and
|
||||
/// position of the child.
|
||||
///
|
||||
/// The [clipBehavior] argument must not be null or [Clip.none].
|
||||
const ClipOval({Key? key, this.clipper, this.clipBehavior = Clip.antiAlias, Widget? child})
|
||||
: assert(clipBehavior != null),
|
||||
super(key: key, child: child);
|
||||
/// The [clipBehavior] argument must not be null. If [clipBehavior] is
|
||||
/// [Clip.none], no clipping will be applied.
|
||||
const ClipOval({
|
||||
Key? key,
|
||||
this.clipper,
|
||||
this.clipBehavior = Clip.antiAlias,
|
||||
Widget? child,
|
||||
}) : assert(clipBehavior != null),
|
||||
super(key: key, child: child);
|
||||
|
||||
/// If non-null, determines which clip to use.
|
||||
///
|
||||
@@ -816,13 +827,11 @@ class ClipOval extends SingleChildRenderObjectWidget {
|
||||
|
||||
@override
|
||||
RenderClipOval createRenderObject(BuildContext context) {
|
||||
assert(clipBehavior != Clip.none);
|
||||
return RenderClipOval(clipper: clipper, clipBehavior: clipBehavior);
|
||||
}
|
||||
|
||||
@override
|
||||
void updateRenderObject(BuildContext context, RenderClipOval renderObject) {
|
||||
assert(clipBehavior != Clip.none);
|
||||
renderObject
|
||||
..clipper = clipper
|
||||
..clipBehavior = clipBehavior;
|
||||
@@ -866,7 +875,8 @@ class ClipPath extends SingleChildRenderObjectWidget {
|
||||
/// consider using a [ClipRect], which can achieve the same effect more
|
||||
/// efficiently.
|
||||
///
|
||||
/// The [clipBehavior] argument must not be null or [Clip.none].
|
||||
/// The [clipBehavior] argument must not be null. If [clipBehavior] is
|
||||
/// [Clip.none], no clipping will be applied.
|
||||
const ClipPath({
|
||||
Key? key,
|
||||
this.clipper,
|
||||
@@ -886,7 +896,6 @@ class ClipPath extends SingleChildRenderObjectWidget {
|
||||
Widget? child,
|
||||
}) {
|
||||
assert(clipBehavior != null);
|
||||
assert(clipBehavior != Clip.none);
|
||||
assert(shape != null);
|
||||
return Builder(
|
||||
key: key,
|
||||
@@ -917,13 +926,11 @@ class ClipPath extends SingleChildRenderObjectWidget {
|
||||
|
||||
@override
|
||||
RenderClipPath createRenderObject(BuildContext context) {
|
||||
assert(clipBehavior != Clip.none);
|
||||
return RenderClipPath(clipper: clipper, clipBehavior: clipBehavior);
|
||||
}
|
||||
|
||||
@override
|
||||
void updateRenderObject(BuildContext context, RenderClipPath renderObject) {
|
||||
assert(clipBehavior != Clip.none);
|
||||
renderObject
|
||||
..clipper = clipper
|
||||
..clipBehavior = clipBehavior;
|
||||
@@ -1014,7 +1021,8 @@ class PhysicalModel extends SingleChildRenderObjectWidget {
|
||||
shape: shape,
|
||||
clipBehavior: clipBehavior,
|
||||
borderRadius: borderRadius,
|
||||
elevation: elevation, color: color,
|
||||
elevation: elevation,
|
||||
color: color,
|
||||
shadowColor: shadowColor,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -87,6 +87,10 @@ void main() {
|
||||
await tester.pumpWidget(const ClipRect(clipBehavior: Clip.antiAlias));
|
||||
|
||||
expect(renderClip.clipBehavior, equals(Clip.antiAlias));
|
||||
|
||||
await tester.pumpWidget(const ClipRect(clipBehavior: Clip.none));
|
||||
|
||||
expect(renderClip.clipBehavior, equals(Clip.none));
|
||||
});
|
||||
|
||||
test('ClipRRect constructs with the right default values', () {
|
||||
@@ -105,6 +109,10 @@ void main() {
|
||||
await tester.pumpWidget(const ClipRRect(clipBehavior: Clip.hardEdge));
|
||||
|
||||
expect(renderClip.clipBehavior, equals(Clip.hardEdge));
|
||||
|
||||
await tester.pumpWidget(const ClipRRect(clipBehavior: Clip.none));
|
||||
|
||||
expect(renderClip.clipBehavior, equals(Clip.none));
|
||||
});
|
||||
|
||||
testWidgets('ClipOval updates clipBehavior in updateRenderObject', (WidgetTester tester) async {
|
||||
@@ -117,6 +125,10 @@ void main() {
|
||||
await tester.pumpWidget(const ClipOval(clipBehavior: Clip.hardEdge));
|
||||
|
||||
expect(renderClip.clipBehavior, equals(Clip.hardEdge));
|
||||
|
||||
await tester.pumpWidget(const ClipOval(clipBehavior: Clip.none));
|
||||
|
||||
expect(renderClip.clipBehavior, equals(Clip.none));
|
||||
});
|
||||
|
||||
testWidgets('ClipPath updates clipBehavior in updateRenderObject', (WidgetTester tester) async {
|
||||
@@ -129,6 +141,10 @@ void main() {
|
||||
await tester.pumpWidget(const ClipPath(clipBehavior: Clip.hardEdge));
|
||||
|
||||
expect(renderClip.clipBehavior, equals(Clip.hardEdge));
|
||||
|
||||
await tester.pumpWidget(const ClipPath(clipBehavior: Clip.none));
|
||||
|
||||
expect(renderClip.clipBehavior, equals(Clip.none));
|
||||
});
|
||||
|
||||
testWidgets('ClipPath', (WidgetTester tester) async {
|
||||
|
||||
Reference in New Issue
Block a user