简体   繁体   English

如何在颤振中创建锯齿状边框

[英]How to create a jagged border in flutter

I want to create a jagged border around a container (see image below).我想在容器周围创建一个锯齿状边框(见下图)。 Anyones know how to do that ?有人知道怎么做吗? Jagged border example锯齿状边框示例

There is a plugin that makes it simple: dotted_border有一个插件可以让它变得简单: dotted_border

Example:例子:

DottedBorder(
    color: Colors.black,
    strokeWidth: 1,
    child: FlutterLogo(size: 148),
)

I found a perfect solution.我找到了一个完美的解决方案。 I use a ClipPath and add a CustomClipper:我使用 ClipPath 并添加一个 CustomClipper:

class HorizontalJaggedBorderClipper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    Path path = Path();
    path.lineTo(size.width, 0);
    double y = 0;
    double x = size.width;
    double increment = size.height / 6;
    double delta = size.height * 0.15;

    while (y < size.height) {
      y += increment;
      x = (x == size.width) ? size.width - delta : size.width;
      path.lineTo(x, y);
    }
    path.lineTo(0, size.height);
    x = 0;
    while (y > 0) {
      x = (x == 0) ? delta : 0;
      y -= increment;
      path.lineTo(x, y);
    }

    path.close();
    return path;
  }

  @override
  bool shouldReclip(CustomClipper oldClipper) {
    return oldClipper != this;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM