parent
a56a407233
commit
78c9aa3071
@ -0,0 +1,37 @@
|
|||||||
|
import 'package:ansu_ui/ansu_ui.dart';
|
||||||
|
import 'package:ansu_ui/chart/circle_chart_widget.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class ExampleChart extends StatefulWidget {
|
||||||
|
const ExampleChart({Key key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_ExampleChartState createState() => _ExampleChartState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ExampleChartState extends State<ExampleChart> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ASScaffold(
|
||||||
|
title: 'chart',
|
||||||
|
body: ListView(
|
||||||
|
children: [
|
||||||
|
20.hb,
|
||||||
|
ListTile(
|
||||||
|
title: Text('circle chart'),
|
||||||
|
trailing: Container(
|
||||||
|
width: 50.w,
|
||||||
|
height: 50.w,
|
||||||
|
child: CircleChart(
|
||||||
|
size: 40.w,
|
||||||
|
color: Colors.red,
|
||||||
|
aboveStrokeWidth: 10.w,
|
||||||
|
core: '65%'.text.size(20.sp).color(kTextColor).make(),
|
||||||
|
aspectRato: 0.65,
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
import 'package:ansu_ui/painters/circle_chart_painter.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
|
||||||
|
class CircleChart extends StatelessWidget {
|
||||||
|
final double? size;
|
||||||
|
|
||||||
|
///角度
|
||||||
|
final double aspectRato;
|
||||||
|
|
||||||
|
///底部圆圈的宽度
|
||||||
|
final double? underStrokeWidth;
|
||||||
|
|
||||||
|
///弧的宽度
|
||||||
|
final double? aboveStrokeWidth;
|
||||||
|
|
||||||
|
///弧的颜色
|
||||||
|
final Color color;
|
||||||
|
|
||||||
|
///圆圈中间显示的组件
|
||||||
|
final Widget core;
|
||||||
|
|
||||||
|
const CircleChart(
|
||||||
|
{Key? key,
|
||||||
|
this.size,
|
||||||
|
required this.aspectRato,
|
||||||
|
this.underStrokeWidth,
|
||||||
|
this.aboveStrokeWidth,
|
||||||
|
required this.color,
|
||||||
|
required this.core})
|
||||||
|
: super(key: key);
|
||||||
|
|
||||||
|
double get customSize => size ?? 100.w;
|
||||||
|
|
||||||
|
double get customUnderWidth => underStrokeWidth ?? 5.w;
|
||||||
|
|
||||||
|
double get customAboveWidth => aboveStrokeWidth ?? 15.w;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SizedBox(
|
||||||
|
width: customSize,
|
||||||
|
height: customSize,
|
||||||
|
child: CustomPaint(
|
||||||
|
painter: CircleChartPainter(
|
||||||
|
underStrokeWidth: customUnderWidth,
|
||||||
|
aboveStrokeWidth: customAboveWidth,
|
||||||
|
radius: aspectRato,
|
||||||
|
aboveColor: color),
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: core,
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class CircleChartPainter extends CustomPainter {
|
||||||
|
final double underStrokeWidth;
|
||||||
|
final double aboveStrokeWidth;
|
||||||
|
final double radius;
|
||||||
|
final Color aboveColor;
|
||||||
|
|
||||||
|
CircleChartPainter(
|
||||||
|
{required this.underStrokeWidth,
|
||||||
|
required this.aboveStrokeWidth,
|
||||||
|
required this.radius,
|
||||||
|
required this.aboveColor});
|
||||||
|
|
||||||
|
@override
|
||||||
|
void paint(Canvas canvas, Size size) {
|
||||||
|
var offset = Offset(size.width / 2, size.height / 2);
|
||||||
|
var paint = Paint()
|
||||||
|
..strokeWidth = underStrokeWidth
|
||||||
|
..style = PaintingStyle.stroke
|
||||||
|
..color = Color(0xFFCECECE);
|
||||||
|
canvas.drawCircle(offset, size.width / 2, paint);
|
||||||
|
paint
|
||||||
|
..strokeWidth = aboveStrokeWidth
|
||||||
|
..strokeCap = StrokeCap.round
|
||||||
|
..color = aboveColor;
|
||||||
|
var rect = Rect.fromCircle(center: offset, radius: size.width / 2);
|
||||||
|
canvas.drawArc(rect, -pi / 2, 2 * pi * radius, false, paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool shouldRepaint(covariant CustomPainter oldDelegate) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue