gpt4 book ai didi

widget - Flutter CustomPaint 阴影

转载 作者:IT王子 更新时间:2023-10-29 07:06:40 30 4
gpt4 key购买 nike

我有以下小部件:

class OutsiderButton extends StatelessWidget {

final Function onPressed;
final Icon icon;
final OutsiderButtonPosition position;

OutsiderButton({this.onPressed, @required this.icon, this.position});

@override
Widget build(BuildContext context) {
return new Stack(fit: StackFit.loose, alignment: Alignment.center, children: [
new CustomPaint(
painter: new _OutsiderShape(position: position),
size: Size(60.0, 60.0),
isComplex: false,
),
OutlineButton(
borderSide: BorderSide(width: 1.0, color: Colors.white),
color: AppThemeColors.accentColor,
shape: new CircleBorder(),
child: new Padding(
padding: const EdgeInsets.all(6.0),
child: icon,
),
onPressed: onPressed,
)
]);
}
}

它使用CustomPainter 绘制背景。我需要这个 CustomPainter 来绘制阴影,但是每次单击小部件时,阴影都会重新绘制并且变得越来越强。这是 CustomPainter:

class _OutsiderShape extends CustomPainter {

final Paint bookMarkPaint;
final double hexagonOffset = 15.0;
final OutsiderButtonPosition position;
Path path = Path();

_OutsiderShape({this.position = OutsiderButtonPosition.TOP}) : bookMarkPaint = new Paint() {
bookMarkPaint.color = AppThemeColors.primaryColorLight;
bookMarkPaint.style = PaintingStyle.fill;
}

@override
void paint(Canvas canvas, Size size) {

canvas.save();

if (position == OutsiderButtonPosition.BOTTOM) {
canvas.rotate(pi);
canvas.translate(-size.width, -size.height);
}

path.moveTo(0.0, hexagonOffset);
path.relativeLineTo(size.width / 3, -hexagonOffset);
path.relativeLineTo(size.width / 3, 0.0);
path.relativeLineTo(size.width / 3, hexagonOffset);
path.relativeLineTo(0.0, size.height - hexagonOffset);
path.relativeLineTo(-size.width, 0.0);
path.close();

canvas.drawShadow(path, Colors.grey[900], 2.0, false);
canvas.drawPath(path, bookMarkPaint);

canvas.restore();
}

@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}

这是点击四次后阴影的样子。

Wrong Shadow

如何避免这种行为?

最佳答案

这一行的问题

//problem here 
canvas.drawShadow(path, Colors.grey[900], 2.0, false)

//change the alpha color of your grey color like this
canvas.drawShadow(path, Colors.grey.withAlpha(50), 4.0, false);

关于widget - Flutter CustomPaint 阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51004325/

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