I am able to clip the image with ClipPath but how can I add a border to that clipped image as following?
ClipPath class Null safety. A widget that clips its child using a path. Calls a callback on a delegate whenever the widget is to be painted. The callback returns a path and the widget prevents the child from painting outside the path.
You can Solve it this way :
CustomPainter
with the same Path
in the CustomClipper<Path>
Example :
Path path = Path();
path.lineTo(0.0, 0.0);
path.lineTo(size.width, 0.0);
path.lineTo(size.width, size.height * 0.8);
path.lineTo(0.0, size.height);
path.close();
Paint
Object and with Stroke painting Style and the strokeWidth
is the width of your custom borderCODE
Paint paint = Paint()
..style = PaintingStyle.stroke
..strokeWidth=10.0
..color = Colors.black;
and finally draw this path in canvas
canvas.drawPath(path, paint);
also you need to make sure that this CustomPaint
is the child of your container
ClipPath(
clipper: traingleclipper(),
child: Container(
color: Colors.white,
child: CustomPaint(
painter: ClipperBorderPainter(),
),
),
)
in my Example this is the result :
also there is another way using a Stack
in this way you will create the image with clipper and then create the CustomPaint
with the same Path
Stack(
children: <Widget>[
ClipPath(
clipper: CustomClip(),
child: Image.network(
"http://www.delonghi.com/Global/recipes/multifry/pizza_fresca.jpg",
width: double.infinity,
height: 400.0,
fit: BoxFit.cover,
)),
CustomPaint(
painter: BorderPainter(),
child: Container(
height: 400.0,
),
),
],
),
Full Example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With