| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import 'dart:math';
- import 'package:fast/utils/global.dart';
- import 'package:fast/utils/size_fit.dart';
- import 'package:flutter/material.dart';
- import 'dart:ui' as ui;
- import '../../constants.dart';
- class ProgressPainter extends CustomPainter {
- Color lineColor;
- Color completeColor;
- double arcAngle;
- double beginAngle;
- double width;
- ui.Image? localImage;
- ProgressPainter(
- {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) {
- if (arcAngle==0){
- return;
- }
- Offset center = Offset(size.width / 2, size.height / 2); // 坐标中心
- double radius = Global().progressWidth; // 半径
-
- Paint progress = Paint()
- ..strokeCap = StrokeCap.round
- ..style = PaintingStyle.stroke
- ..strokeWidth = width;
-
- var step = 0.171;
- var maxEnd = arcAngle;
- if (maxEnd>2*pi-step){
- maxEnd = 2*pi-2*step;
- }
- progress.shader = ui.Gradient.sweep(center, [const Color(0x33AAFF00), kThemeColor],[0,1],ui.TileMode.clamp,step,maxEnd+step,null);
- canvas.drawArc(Rect.fromCircle(center: center, radius: radius), step, maxEnd,
- false, progress);
- // Paint line = Paint()
- // ..color = lineColor
- // ..strokeCap = StrokeCap.round
- // ..style = PaintingStyle.stroke
- // ..strokeWidth = width + 8;
- // if (localImage != null) {
- // double startLeft = center.dx + radius * cos(maxEnd+step);
- // double startTop = center.dy + radius * sin(maxEnd+step);
- // 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;
- }
|