| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- import 'package:fast/utils/global.dart';
- import 'package:flutter/material.dart';
- import 'package:fast/utils/size_fit.dart';
- import 'dart:ui' as ui;
- import 'dart:math';
- class TargetPainter extends CustomPainter {
- Color lineColor;
- Color completeColor;
- double arcAngle;
- double beginAngle;
- double width;
- ui.Image? localImage;
- TargetPainter(
- {required this.lineColor,
- required this.completeColor,
- required this.arcAngle,
- required this.beginAngle,
- required this.width,
- required this.localImage});
- @override
- void paint(Canvas canvas, Size size) {
- Paint line = Paint()
- ..color = lineColor
- ..strokeCap = StrokeCap.round
- ..style = PaintingStyle.stroke
- ..strokeWidth = width + 8;
- Paint complete = Paint()
- // ..color = completeColor
- ..strokeCap = StrokeCap.round
- ..style = PaintingStyle.stroke
- ..strokeWidth = width;
- Offset center = Offset(size.width / 2, size.height / 2); // 坐标中心
- double radius = Global().progressWidth; // 半径
- double begin = beginAngle;
- if (begin>2*pi){
- begin -= 2*pi;
- }
- if (begin>pi){
- begin -= 2*pi;
- }
- if (arcAngle>2*pi && begin<0){
- arcAngle -= 2*pi;
- }
- if (begin>0 && arcAngle<begin){
- arcAngle += 2*pi;
- }
- if (arcAngle<-pi){
- arcAngle += 2*pi;
- }
- double end = arcAngle-begin;
- if (end>2*pi){
- end -= 2*pi;
- }
-
- // if (begin < 0 && end > 2 * pi + (pi / 2 + begin)) {
- // end -= 2 * pi;
- // }
- complete.color = const Color(0x26C4CCDA);
- canvas.drawArc(Rect.fromCircle(center: center, radius: radius), begin, end,
- false, complete);
- // if (localImage != null) {
- // double startLeft = center.dx + radius * cos(begin);
- // double startTop = center.dy + radius * sin(begin);
- // double? width = localImage?.width.toDouble();
- // double? height = localImage?.height.toDouble();
- // canvas.drawImageRect(
- // localImage!,
- // Rect.fromLTWH(0, 0, width!, height!),
- // Rect.fromLTWH(startLeft - (width / 6).px, startTop - (height / 6).px,
- // (width / 3).px, (height / 3).px),
- // line);
- // }
- }
- void setCanvasImageData(Canvas canvas) {}
- @override
- bool shouldRepaint(CustomPainter oldDelegate) => true;
- }
|