flutter - Flutter - 如何创建自定义形状
问题描述
下面的图像是我想要使用带有 LinearGradient 的 CustomPainter 绘制并有阴影的图像
我已经画了波纹管形状但不一样并且有LinearGradient
class CurvePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
Rect rect = new Rect.fromCircle(
center: new Offset(165.0, 55.0),
radius: 180.0,
);
final Gradient gradient = new LinearGradient(
colors: <Color>[
const Color(0xFF2151a6),
const Color(0xFF3377f4),
],
);
var paint = Paint()..shader = gradient.createShader(rect);
paint.color = Colors.green[800];
paint.style = PaintingStyle.fill; // Change this to fill
var path = Path();
path.moveTo(0, size.height * 0.35);
path.moveTo(0, size.height * 0.3);
path.quadraticBezierTo(
size.width / 2, size.height / 2.4, size.width, size.height * 0.35);
path.lineTo(size.width, 0);
path.lineTo(0, 0);
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}
解决方案
我觉得我画的不错
尝试这个:
class CurvePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
Rect rect = new Rect.fromCircle(
center: new Offset(165.0, 55.0),
radius: 180.0,
);
final Gradient gradient = new LinearGradient(
colors: <Color>[
const Color(0xFF2151a6),
const Color(0xFF3377f4),
],
);
var paint = Paint()..shader = gradient.createShader(rect);
paint.color = Colors.green[800];
paint.style = PaintingStyle.fill; // Change this to fill
var path = Path();
path.moveTo(0, size.height * 0.32);
path.lineTo(size.width * 0.20, size.height * 0.34);
path.quadraticBezierTo( size.width * 0.30, size.height * 0.35,
size.width * 0.40, size.height * 0.34 );
path.lineTo(size.width*0.9, size.height * 0.26);
path.quadraticBezierTo( size.width, size.height * 0.24,
size.width , size.height * 0.20);
path.lineTo(size.width, 0);
path.lineTo(0 , 0);
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}
推荐阅读
- r - 在包开发期间查找未使用/“孤立”的非导出对象
- azure - 使用 for_each 创建不同数量的具有唯一 NIC 的 VM
- python - Django 过滤器 - 我想对上一个查询进行排序,而不是对整个模型进行排序
- asp.net - 文件上传并保存在 ASP.NET MVC 中的数据库中
- android - 在点击 Nativescript Angular + LineSeparator 颜色时删除 ListView 项目突出显示?
- wpf - .Net Core (WPF) 和单个 exe 中的应用程序设置
- java - 使用 javamail 将字符串作为附件发送会得到重复的内容
- javascript - 页面大小更改后丢失光标位置
- android - (Ionic 3) 后台模式插件停止 iOS 设备上媒体的后台播放
- json - Azure IoT Hub 中的消息路由返回 application/octet-stream