我爱模板网 > 建站教程 > dart >  dart笔记5:重构override+画圆正文

dart笔记5:重构override+画圆

dart笔记5:重构override+画圆
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'override重构',
      home: Scaffold(
        appBar: AppBar(
          title: Text('override重构'),
        ),
        body: Center(
          child: SizedBox(
            width: 500.0,
            height: 500.0,
            child: CustomPaint(
              painter: CirclePainter(),
              child: Center(
                child: Text(
                  '绘制圆',
                  style: TextStyle(
                    fontSize: 38.0,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

class CirclePainter extends CustomPainter {
  Paint _paint = Paint()
    ..color = Colors.grey
    ..strokeCap = StrokeCap.square
    ..isAntiAlias = true
    ..strokeWidth = 3.0
    ..style = PaintingStyle.stroke;

  @override
  void paint(Canvas canvas, Size size) {
    canvas.drawCircle(Offset(200.0, 150.0), 150.0, _paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return false;
  }
}



部分素材资源来源网站,本站提供免费下载,如有侵权请联系站长马上删除!
上一篇:dart笔记4:flutter折叠菜单 下一篇:dart笔记6:重写操作符
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
选择头像:
最新评论

猜你喜欢