import 'package:flutter/material.dart'; class CrossPaint extends StatelessWidget { @override Widget build(BuildContext context) { return Container( color: Colors.transparent, alignment: Alignment.center, child: CustomPaint( // 使用CustomPaint 背景画板 painter: MyPainter(), ), ); } } class MyPainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { // 创建画笔 final Paint paintLine = Paint() ..color = Colors.white ..strokeWidth = 2; // 绘制线 canvas.drawLine(const Offset(-400, 0), const Offset(400, 0), paintLine); canvas.drawLine(const Offset(0, 500), const Offset(0, -440), paintLine); // 创建画笔 // final Paint paintPoint = Paint()..color = Colors.red; // 绘制圆点 // canvas.drawCircle(Offset(0, 0), 10, paintPoint); } @override bool shouldRepaint(CustomPainter oldDelegate) => false; }