簡體   English   中英

如何從右上角而不是左上角開始 CustomClipper (ClipPath)

[英]How can I start a CustomClipper (ClipPath) from top right and NOT top left

我的 CustomClipper 從左上角開始,但是,我希望它從右上角開始。 這是我的代碼: Clipper:

class ProfileBarClipper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    var path = new Path();
    path.lineTo(0, size.height - 50);
    var controllPoint = Offset(50, size.height);
    var endPoint = Offset(size.width / 2, size.height);
    path.quadraticBezierTo(
        controllPoint.dx, controllPoint.dy, endPoint.dx, endPoint.dy);
    path.lineTo(size.width, size.height);
    path.lineTo(size.width, 0);

    return path;
  }

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

ProfileBarClipper()的用法:

ClipPath(
    clipper: ProfileBarClipper(),
    child: Container(
        color: Colors.white,
        height: 200,
    ),
)

這是此代碼的圖像: https://i.stack.imgur.com/rVsL3.png

使用moveTo

像這樣。

var path = new Path();
path.moveTo(size.width,0); // (size.width, 0) means top right

更新:檢查一下...

class ProfileBarClipper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    var path = new Path();
    path.moveTo(size.width, 0);
    path.lineTo(size.width, size.height - 50);
    var controllPoint = Offset(size.width-50, size.height);
    var endPoint = Offset(size.width / 2, size.height);
    path.quadraticBezierTo(
        controllPoint.dx, controllPoint.dy, endPoint.dx, endPoint.dy);
    path.lineTo(0, size.height);
    path.lineTo(0, 0);

    return path;
  }

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

output:

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM