【问题标题】:Flutter: Can't make a ClipPath颤振:无法制作剪辑路径
【发布时间】:2021-05-31 12:46:15
【问题描述】:

有人可以帮我解决 Flutter 中的这个 ClipPath 吗?

我无法制作底部边框。

另外,我怎样才能让它作为 Row 孩子可见?

我注意到它可以在 Container 中使用,但是当我将 Container(或 Flexible)拖到 Row 中或没有小部件时它不起作用。

更新

这是 ClipPath 不可见时的返回

Scaffold(
  body: SafeArea(
    child: Row(
      children: [
        Flexible(
          child: ClipPath(
            clipper: AuthClipPath(),
            child: Container(
            height: size.height * .75,
            decoration: BoxDecoration(gradient: gradient),
            child: authForm(),
            ),
          ),
        )
      ],
    ),
  ),
)

这是 ClipPath 可见时的返回

Scaffold(
  body: SafeArea(
    child: Container(
      child: ClipPath(
        clipper: AuthClipPath(),
        child: Container(
        height: size.height * .75,
        decoration: BoxDecoration(gradient: gradient),
        child: authForm(),
      ),
    ),
  )       
)

这是来自 ClipPath 的剪辑器类

class AuthClipPath extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    Path path = Path();
    path.lineTo(0.0, size.height - 30);

    Offset firstControlPoint = Offset(size.width / 4, size.height);
    Offset firstPoint = Offset(size.width / 2, size.height);

    path.quadraticBezierTo(firstControlPoint.dx, firstControlPoint.dy,
        firstPoint.dx, firstPoint.dy);

    Offset secondControlPoint = Offset(size.width / 4 * 3, size.height);
    Offset secondPoint = Offset(size.width, size.height - 30);

    path.quadraticBezierTo(secondControlPoint.dx, secondControlPoint.dy,
        secondPoint.dx, secondPoint.dy);

    path.lineTo(size.width, 0.0);
    path.close();

    return path;
  }

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

灵活的小部件与可见性无关。

谢谢!

【问题讨论】:

  • 你能分享一下它是如何工作的代码吗?
  • 我添加了返回码,当它工作时,当它不工作时。如果提供整个文件会有所帮助,请说,我将创建一个 Git Repo,但我认为这无关紧要,因为这是我必须进行的唯一更改才能使 ClipPath 可见。感谢您查看代码!

标签: flutter dart mobile


【解决方案1】:

Row() 中像这样使用你的AuthClipPath()

home: Scaffold(
    body: SafeArea(
      child: Row(
        children: [
          Flexible(
            child: ClipPath(
              clipper: AuthClipPath(),
              child: Container(
                height: 300,
                color: Colors.amber.shade200,
              ),
            ),
          ),
        ],
      ),
    ),
  ),

你可以像这样实现波浪效果。您可以随时根据需要进行调整。

Path path = Path();
path.moveTo(size.width, 0);
path.lineTo(0, 0);
path.quadraticBezierTo(
    0, size.height * 0.4500000, 0, size.height * 0.6000000);
path.cubicTo(
    size.width * 0.3000000,
    size.height * 0.9000000,
    size.width * 0.7000000,
    size.height * 0.3000000,
    size.width,
    size.height * 0.6000000);
path.quadraticBezierTo(
    size.width, size.height * 0.4500000, size.width, 0);
path.close();

return path;

【讨论】:

  • 我现在解决了:) 显然,是因为 authForm() 中的一个元素超出了 Row 小部件。你知道制作自定义 ClipPath 吗?如果你这样做,你能帮我解决上面的路径吗?
  • 是的,当然,检查我用你的波浪效果更新的代码,只需粘贴这些行。
  • 哇!非常感谢!!
猜你喜欢
  • 2020-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-15
  • 2019-02-19
  • 1970-01-01
相关资源
最近更新 更多