将阴影添加到从容器创建的ClipPath-Flutter

时间:2020-09-06 11:25:32

标签: flutter flutter-layout shadow clip-path flutter-widget

我想在我从Container创建的ClipPath中添加阴影。 这是我创建的ClipPath:

              ClipPath(
                clipper: RibbonClipper(),
                child: Container(
                  height: 20,
                  width: 80,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(5.0),
                      bottomLeft: Radius.circular(5.0),
                    ),
                    color: Color(0xFF338D5E),
                  ),
                ),
              ), 

CustomClipper路径为:

  @override
  Path getClip(Size size) {
    var path = Path();
    path.lineTo(0, size.height);
    path.lineTo(size.width, size.height);
    path.lineTo(size.width * .90, size.height * .5);
    path.lineTo(size.width, 0);
    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) {
    return true;
  }
}

1 个答案:

答案 0 :(得分:0)

我不得不这样做。我发现this very useful gist结合了ClipPath和阴影。另外,似乎有人made it a package,但我没有测试它。