I am trying to paint a icon with green color. I am using custom painter class.
Sample code:
import 'dart:ui';
import 'package:flutter/material.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
double x = 0.0;
double y = 0.0;
List<Offset> mark = [];
void updatePosition(TapDownDetails details) {
x = details.localPosition.dx;
y = details.localPosition.dy;
setState(() {
mark.add(Offset(x, y));
print("mark:$mark");
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: GestureDetector(
onTapDown: updatePosition,
child: RepaintBoundary(
child: Container(
margin: const EdgeInsets.only(left: 8, right: 8),
height: 300,
width: double.infinity,
decoration: BoxDecoration(
border: Border.all(color: Colors.blue),
image: const DecorationImage(
image: AssetImage(
'assets/dark.jpg',
),
fit: BoxFit.cover)),
child: CustomPaint(
painter: MyCustomPainter(mark),
),
)),
),
),
);
}
}
class MyCustomPainter extends CustomPainter {
final List<Offset> marks;
const MyCustomPainter(this.marks);
@override
void paint(Canvas canvas, Size size) async {
Paint paint = Paint()
..color = Colors.green
..strokeCap = StrokeCap.round
..strokeWidth = 15.0;
canvas.drawPoints(PointMode.points, marks, paint);
}
@override
bool shouldRepaint(MyCustomPainter oldDelegate) {
return true;
}
}
It's helped me to draw a points list. How can I draw a list of location icon instead of green points?