Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a border to a clipped image?

I am able to clip the image with ClipPath but how can I add a border to that clipped image as following?

enter image description here

like image 869
Figen Güngör Avatar asked Jul 08 '18 13:07

Figen Güngör


People also ask

How do you use clip path in flutter?

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.


1 Answers

You can Solve it this way :

  1. create a 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();
  1. create a Paint Object and with Stroke painting Style and the strokeWidth is the width of your custom border

CODE

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 :

enter image description here

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,
              ),
            ),
          ],
        ),

enter image description here Full Example

like image 167
Raouf Rahiche Avatar answered Sep 26 '22 14:09

Raouf Rahiche