import 'package:flutter/material.dart'; import 'package:trackoffical_app/screen.dart'; import 'dart:ui' as ui; class MyPositionPoint extends StatelessWidget{ const MyPositionPoint({ super.key, required this.offset, required this.color, this.radius, this.direction }); final Color color; final Offset offset; final double? radius; final double? direction; @override Widget build(BuildContext context) { final width = radius??6.62.wp; final height = width*3.3; final hasDirection = direction!= null; Widget child = CustomPaint( painter: _LayerMyPositionPointPainter(color, hasDirection, 255), size: Size(width, height), ); if(hasDirection){ child = Transform.rotate( angle: direction!, alignment: Alignment.center, child: child); } return Positioned( left: offset.dx-width/2, top: offset.dy-height/2, child: child); } } class _LayerMyPositionPointPainter extends CustomPainter { final Color color; final bool hasDirection; final int alpha; _LayerMyPositionPointPainter( this.color, this.hasDirection, this.alpha ); @override void paint(Canvas canvas, Size size) { final paint = Paint(); drawMyLocation(canvas, paint, size); } @override bool shouldRepaint(CustomPainter oldDelegate) => false; drawMyLocation(Canvas canvas, Paint paint, Size size) { final color = this.color.withAlpha(alpha); final color2 = this.color.withAlpha((alpha*0.8).toInt()); final center = Offset(size.width/2, size.height/2); paint.color = color; var rect = Rect.fromLTRB(0 , 0, size.width, center.dy); paint.shader = ui.Gradient.linear(rect.topCenter, rect.bottomCenter, [ const Color(0x00FFFFFF), color2 ], [ 0, 1, ]); final path = Path(); path.moveTo(rect.topLeft.dx, rect.topLeft.dy); path.lineTo(rect.topRight.dx, rect.topRight.dy); path.lineTo(rect.bottomCenter.dx, rect.bottomCenter.dy); canvas.drawPath(path, paint); paint.shader = null; paint.color = Colors.white.withAlpha(alpha); canvas.drawCircle(center, center.dx* 0.8, paint); paint.color = color; canvas.drawCircle(center, center.dx * 0.5, paint); } } void main(){ runPreview(Scaffold( backgroundColor: Colors.white, appBar: AppBar(title: const Text('data'),), body:const SizedBox( height: double.infinity, width: double.infinity, child: Stack( children: [ MyPositionPoint(offset: Offset(200, 200), color: Colors.red, direction: 0,) ], ), ) )); }