MyPainter.dart 1.1 KB
import 'dart:math';

import 'package:flutter/material.dart';

class MyPainter extends CustomPainter {

  @override
  void paint(Canvas canvas, Size size) {
    var paint = Paint()
      ..isAntiAlias = true
      ..strokeWidth=1.0
      ..style=PaintingStyle.fill
      ..color=Colors.grey[700]
      ..invertColors=false;

    Paint line = Paint()
      ..color = Colors.grey[700]
      ..strokeCap = StrokeCap.round
      ..style = PaintingStyle.stroke
      ..strokeWidth = 5;

    double cx=size.width/2,cy=size.height/2;
//    double radius=size.width/4;
    Offset center = Offset(size.width/2, 0);  //  坐标中心
    double radius = min(size.width/6, size.height/6);  //  半径、
    canvas.drawCircle(
        center,
        radius,
        line
    );

    Rect rect =  Rect.fromCircle(center: center, radius: radius);

//    Rect rect =Rect.fromLTRB(50.0, 50.0, size.width-50.0, size.height);
//    canvas.drawRect(rect, paint);

  }

  //在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
  @override
  bool shouldRepaint(CustomPainter oldDelegate) => true;
}