it is possible to reverse the container BorderRadius in flutter

138

You can follow this ClipPath

For left corner

class CustomCornerClipPath extends CustomClipper<Path> {
  final double cornerR;
  const CustomCornerClipPath({this.cornerR = 16.0});

  @override
  Path getClip(Size size) => Path()
    ..lineTo(size.width, 0)
    ..lineTo(
      size.width,
      size.height - cornerR,
    )
    ..arcToPoint(
      Offset(
        size.width - cornerR,
        size.height,
      ),
      radius: Radius.circular(cornerR),
      clockwise: false,
    )
    ..lineTo(0, size.height);

  @override
  bool shouldReclip(covariant CustomClipper<Path> oldClipper) => false;
}

And use

ClipPath(
  clipper: const CustomCornerClipPath(),
  child: Container(
    height: 100, //based on your need
    width: 100,
    color: Colors.cyanAccent,
  ),
),

enter image description here


For the right corner, path will be

@override
Path getClip(Size size) => Path()
  ..lineTo(size.width, 0)
  ..lineTo(size.width, size.height)
  ..lineTo(cornerR, size.height)
  ..arcToPoint(
    Offset(
      0,
      size.height - cornerR,
    ),
    radius: Radius.circular(cornerR),
    clockwise: false,
  );

enter image description here

I will recommend visiting cliprrect-clippath-in-flutter

Share:
138
Mohammed Hamdan
Author by

Mohammed Hamdan

Updated on January 03, 2023

Comments

  • Mohammed Hamdan
    Mohammed Hamdan over 1 year

    i am trying to make layout like this

    enter image description here

    i need the bottomRight corner at other side ..

    i tried this but it does not work

     Container(
                      width: 200
                        height: 200
                        decoration: BoxDecoration(
                            borderRadius: const BorderRadius.only(bottomRight: 
                            Radius.circular(40),),),
                          color:  Colors.deepPurple[900]!,
                        ),
    
                      ),
    

    does it possible in flutter frame work ?

    • Arbiter Chil
      Arbiter Chil about 2 years
      Custom Clippath is your looking for but if you want something you don't need to to do the numbers for each sides. Try a package called flutter_custom_clippers and try the SideCutClipper and explore or play with it
    • Mohammed Hamdan
      Mohammed Hamdan about 2 years
      thanks , but this package does not offer the wanted layout since i have seen this package before
    • Arbiter Chil
      Arbiter Chil about 2 years
      Does the layout below is circle? or a look like a bite?
    • Mohammed Hamdan
      Mohammed Hamdan about 2 years
      circle Exactly ......
  • Mohammed Hamdan
    Mohammed Hamdan about 2 years
    thanks that's what we got from experience but the wanted BorderRadius is 40 , is it possible ?
  • Yeasin Sheikh
    Yeasin Sheikh about 2 years
    you can pass than using cornerR
  • Mohammed Hamdan
    Mohammed Hamdan about 2 years
    can you please edit the answer to make corner in the bottom left and not bottom right, i spent 3 hours trying to handle this but could not , thanks
  • Yeasin Sheikh
    Yeasin Sheikh about 2 years
    glad to help out, play with Path there are other method can be used.