gpt4 book ai didi

Flutter 自定义裁剪器半径

转载 作者:IT王子 更新时间:2023-10-29 06:56:09 24 4
gpt4 key购买 nike

我正在尝试通过 FLutter 中的自定义剪辑器制作自定义剪辑器,但我不知道如何在我的形状中添加一些圆角

左侧为所需结果的屏幕截图,右侧为我的结果: lu

这是我的剪辑代码

class SideArrowClip extends CustomClipper<Path> {
@override
Path getClip(Size size) {
final Path path = Path();
final double startMargin = size.width / 14;
final double s1 = size.height * 0.4;
final double s2 = size.height * 0.6;
print('S1:$s1 SH:${size.height / 2} S2:$s2');
path.lineTo(startMargin, 0);
path.lineTo(startMargin, s1);
path.lineTo(0, size.height / 2);
path.lineTo(startMargin, s2);
path.lineTo(startMargin, size.height);
path.lineTo(size.width, size.height);
path.lineTo(size.width, 0);
path.close();
return path;
}

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

最佳答案

我使用 addRRect(RRect.fromRectAndRadius 来制作圆角矩形

import 'package:flutter/material.dart';

class SideArrowClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
final double width = size.width;
final double height = size.height;
final double startMargin = width / 14;

final double s1 = height * 0.3;
final double s2 = height * 0.7;
final Path path = Path()
..addRRect(RRect.fromRectAndRadius(
Rect.fromLTWH(startMargin, 0, width-startMargin, height),
const Radius.circular(5)))
..lineTo(startMargin, s1)
..lineTo(0, size.height / 2)
..lineTo(startMargin, s2)
..close();
return path;
}

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

关于Flutter 自定义裁剪器半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57028510/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com