process_bar.dart 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import 'dart:math';
  2. import 'package:flutter/material.dart';
  3. class ProcessBar extends StatelessWidget{
  4. final double process;
  5. final int pointCount;
  6. const ProcessBar({super.key, required this.process, required this.pointCount});
  7. @override
  8. Widget build(BuildContext context) {
  9. return Container(
  10. decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(7)),
  11. height: 227,
  12. width: 14,
  13. padding: const EdgeInsets.all(2),
  14. child: CustomPaint(painter: Pentagram(process, pointCount)),
  15. );
  16. }
  17. }
  18. class Pentagram extends CustomPainter {
  19. Pentagram(this.process, this.pointCount);
  20. final double process;
  21. final int pointCount;
  22. @override
  23. void paint(Canvas canvas, Size size) {
  24. var radius = 7.0;
  25. var process = min(this.process, 1.0);
  26. process = max(process, 0.0);
  27. var height = size.height * (1-process);
  28. var paint = Paint()..color = const Color(0xffd8d8d8);
  29. var rect = Offset.zero & Size(size.width, height);
  30. var rRect = RRect.fromRectXY(rect, radius, radius);
  31. canvas.drawRRect(rRect, paint);
  32. paint.color = const Color(0xffff870d);
  33. rect = Offset(0, height) & Size(size.width, size.height - height);
  34. rRect = RRect.fromRectXY(rect, radius, radius);
  35. canvas.drawRRect(rRect, paint);
  36. final xCenter = size.width /2;
  37. final pointCount = min(this.pointCount, 20);
  38. // final pointCount = 20;
  39. paint.color = const Color(0xffffffff).withAlpha(125);
  40. radius = 3;
  41. var padding = 3.0;
  42. if (pointCount >1){
  43. var space = (size.height - (padding+ radius) *2)/(pointCount-1);
  44. var offset = Offset(xCenter, padding + radius);
  45. for (var i = 0; i < pointCount; i++){
  46. canvas.drawCircle(offset, radius, paint);
  47. offset += Offset(0, space);
  48. }
  49. }
  50. paint.color = const Color(0xffd8d8d8).withAlpha(50);
  51. radius = 10;
  52. var offset = Offset(xCenter, height);
  53. canvas.drawCircle(offset, radius, paint);
  54. radius = 8;
  55. paint.color = Colors.white;
  56. offset = Offset(xCenter, height);
  57. canvas.drawCircle(offset, radius, paint);
  58. paint.color = const Color(0xffff0000);
  59. final path = Path();
  60. path.moveTo(xCenter, height-5);
  61. path.lineTo(xCenter+4, height+4);
  62. path.lineTo(xCenter-4, height+4);
  63. path.close();
  64. canvas.drawPath(path, paint);
  65. }
  66. @override
  67. bool shouldRepaint(covariant CustomPainter oldDelegate) {
  68. return false;
  69. }
  70. }