Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振将自定义小部件推到布局外部_Flutter_Flutter Layout - Fatal编程技术网

Flutter 颤振将自定义小部件推到布局外部

Flutter 颤振将自定义小部件推到布局外部,flutter,flutter-layout,Flutter,Flutter Layout,我有一个自定义小部件(这是布局实现) 这是容器的子容器。我现在希望这个小部件以30%的价格推出。这里是一个可视化 我试着剪掉它,然后使用一些空白,但它不起作用。在Android Studio中,我只需将Android:layout_marginBottom=“-50dp”放在我的自定义视图中,但如果填充的值为负值,则会抛出错误 I/flatter(6808):'package:flatter/src/rendering/shift_-box.dart':失败的断言:第107行位置15: I/f

我有一个自定义小部件(这是布局实现)

这是
容器的子容器。我现在希望这个小部件以30%的价格推出。这里是一个可视化

我试着剪掉它,然后使用一些空白,但它不起作用。在Android Studio中,我只需将
Android:layout_marginBottom=“-50dp”
放在我的自定义视图中,但如果填充
的值为负值,则会抛出错误

I/flatter(6808):'package:flatter/src/rendering/shift_-box.dart':失败的断言:第107行位置15:

I/flatter(6808):“padding.isNonNegative”:不正确

编辑:解决方案如下

return ClipRect(
  clipper: myClipper(), //optional
  child: OverflowBox(
    minHeight: ITEM_HEIGHT * 1.5,
    maxHeight: ITEM_HEIGHT * 2,
    child: CustomPaint(
      size: Size(double.infinity, ITEM_HEIGHT * 1.5),
      painter: OvalPainter()
    ),
  ),
);

因此,我将小部件设置为大于空间,然后将其剪裁我使用
CustomClipper
制作了类似的东西,这就是你想要的吗

这是带有
CustomClipper

class OvalClipper extends CustomClipper<Path> {
  static const double PAD = 20;

  @override
  Path getClip(Size size) {
    Path path = Path();

    path.addOval(
      Rect.fromCenter(
        center: Offset(size.width / 2, size.height * 0.7),
        width: size.width - 2 * PAD,
        height: size.height,
      ),
    );

    return path;
  }

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

你能分享OvalInter类和当前的屏幕截图吗?真正的类是其他的,我只是在这里用一个椭圆形来说明它,所以要清楚我想要什么可见。如果你想剪辑它,请使用绘画方法中的
Canvas.clip*()
method中的一个?嗯,我不想每次都看到70%的椭圆形,当我点击容器时,我想打开一个显示整个椭圆形的新页面。在本例中,我所说的容器是一个列表项,因此我在彼此下方显示多个椭圆形,但我不会完全显示它们,以将spacepass保存为有效高度,而不是无穷大,您将能够剪辑在
CustomPainter
中绘制的内容,类似这样的内容是的,但椭圆形的顶部仍应达到容器的顶部。(即椭圆形比容器大,但部分位于容器外部)
class OvalClipper extends CustomClipper<Path> {
  static const double PAD = 20;

  @override
  Path getClip(Size size) {
    Path path = Path();

    path.addOval(
      Rect.fromCenter(
        center: Offset(size.width / 2, size.height * 0.7),
        width: size.width - 2 * PAD,
        height: size.height,
      ),
    );

    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) => true;
}
Container(
  width: 200,
  height: 200,
  color: Colors.green,
  child: ClipPath(
    clipper: OvalClipper(),
    child: Container(
        color: Colors.red,
      ),
    ),
)