widget_point.dart 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import 'dart:typed_data';
  2. import 'package:flutter/material.dart';
  3. import 'package:trackoffical_app/generated/assets.dart';
  4. import 'package:trackoffical_app/screen.dart';
  5. class WidgetPoint extends StatelessWidget {
  6. final double width;
  7. final double height;
  8. final Color color;
  9. final Uint8List? imageBytes;
  10. const WidgetPoint(
  11. {super.key,
  12. required this.width,
  13. required this.height,
  14. required this.color,
  15. this.imageBytes
  16. });
  17. @override
  18. Widget build(BuildContext context) {
  19. final headRadius = width * 0.36;
  20. final headMargin = width/2 - headRadius;
  21. DecorationImage? image;
  22. if(imageBytes!= null){
  23. image = DecorationImage(image: MemoryImage(imageBytes!));
  24. }else{
  25. image = const DecorationImage(image: AssetImage(Assets.imagesImDefaultHead), fit: BoxFit.fill);
  26. }
  27. return Stack(
  28. children: [
  29. SizedBox(
  30. width: width,
  31. height: height,
  32. child: CustomPaint(painter: _Painter(color))),
  33. Positioned(
  34. left: headMargin,
  35. top: headMargin,
  36. child: Container(
  37. width: headRadius*2,
  38. height: headRadius*2,
  39. decoration: BoxDecoration(
  40. border: Border.all(color: Colors.white, width: 0.25.wp),
  41. shape: BoxShape.circle,
  42. image: image,
  43. ),
  44. )
  45. )
  46. ],
  47. );
  48. }
  49. }
  50. class _Painter extends CustomPainter {
  51. _Painter(this.color);
  52. final Color color;
  53. final _paint = Paint();
  54. @override
  55. void paint(Canvas canvas, Size size) {
  56. final lineWidth = size.width * 0.04;
  57. draw(canvas, size, Colors.white, 0);
  58. draw(canvas, size, color, lineWidth);
  59. }
  60. void draw(Canvas canvas, Size size, Color color, double lineWidth) {
  61. _paint.color = color;
  62. _paint.style = PaintingStyle.fill;
  63. final radius = (size.width - lineWidth * 2) / 2;
  64. canvas.drawCircle(
  65. Offset(radius + lineWidth, radius + lineWidth), radius, _paint);
  66. final w = size.width / 3 - lineWidth * 2;
  67. final path = Path();
  68. var x = lineWidth;
  69. var y = lineWidth;
  70. x = (size.width - w) / 2;
  71. y += radius * 1.5;
  72. path.moveTo(x, y);
  73. x += w;
  74. path.lineTo(x, y);
  75. x = size.width / 2;
  76. y = size.height - lineWidth * 2;
  77. path.lineTo(x, y);
  78. path.close();
  79. canvas.drawPath(path, _paint);
  80. }
  81. @override
  82. bool shouldRepaint(covariant CustomPainter oldDelegate) {
  83. return false;
  84. }
  85. }
  86. void main() {
  87. runPreview(Center(
  88. child: WidgetPoint(
  89. width: 140,
  90. height: 210,
  91. color: Colors.red,
  92. )));
  93. }