Skip to content

Commit f818ef6

Browse files
committed
新增CustomPaint Progress组件
1 parent 4e3614c commit f818ef6

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import 'dart:math' as math;
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:flutter_dojo/common/main_title_widget.dart';
5+
6+
class CustomProgressWidget extends StatefulWidget {
7+
@override
8+
_CustomProgressWidgetState createState() => _CustomProgressWidgetState();
9+
}
10+
11+
class _CustomProgressWidgetState extends State<CustomProgressWidget> with SingleTickerProviderStateMixin {
12+
AnimationController controller;
13+
14+
@override
15+
void initState() {
16+
super.initState();
17+
controller = AnimationController(
18+
vsync: this,
19+
duration: Duration(milliseconds: 1000),
20+
)..repeat();
21+
}
22+
23+
@override
24+
void dispose() {
25+
controller.dispose();
26+
super.dispose();
27+
}
28+
29+
@override
30+
Widget build(BuildContext context) {
31+
return Column(
32+
children: <Widget>[
33+
MainTitleWidget('使用CustomPaint绘制进度'),
34+
SizedBox(height: 20),
35+
Container(
36+
width: 100,
37+
height: 100,
38+
child: AnimatedBuilder(
39+
animation: controller,
40+
builder: (context, child) {
41+
return CustomPaint(
42+
painter: ProgressPainter(controller),
43+
);
44+
},
45+
),
46+
),
47+
],
48+
);
49+
}
50+
}
51+
52+
class ProgressPainter extends CustomPainter {
53+
double startAngle;
54+
double sweepAngle;
55+
final AnimationController controller;
56+
57+
ProgressPainter(this.controller) {
58+
startAngle = Tween(begin: math.pi * 1.5, end: math.pi * 3.5)
59+
.chain(CurveTween(curve: Interval(0.5, 1.0)))
60+
.evaluate(controller);
61+
sweepAngle = math.sin(controller.value * math.pi) * math.pi;
62+
}
63+
64+
@override
65+
void paint(Canvas canvas, Size size) {
66+
double side = math.min(size.width, size.height);
67+
Paint paint = Paint()
68+
..color = Colors.blue
69+
..strokeCap = StrokeCap.round
70+
..strokeWidth = 8
71+
..style = PaintingStyle.stroke;
72+
canvas.drawArc(
73+
Offset.zero & Size(side, side),
74+
startAngle,
75+
sweepAngle,
76+
false,
77+
paint,
78+
);
79+
}
80+
81+
@override
82+
bool shouldRepaint(ProgressPainter other) {
83+
return startAngle != other.startAngle || sweepAngle != other.sweepAngle;
84+
}
85+
}

lib/modle/animation/animation_category.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:flutter_dojo/animation/animbutton/progressbutton.dart';
1111
import 'package:flutter_dojo/animation/animlist/animlist.dart';
1212
import 'package:flutter_dojo/animation/animlist/deleteanimlist.dart';
1313
import 'package:flutter_dojo/animation/barchat/bar.dart';
14+
import 'package:flutter_dojo/animation/loading/customprogress.dart';
1415
import 'package:flutter_dojo/animation/loading/loading.dart';
1516
import 'package:flutter_dojo/animation/physical/physical.dart';
1617
import 'package:flutter_dojo/animation/scrollanimation/listtopbottom.dart';
@@ -91,6 +92,13 @@ List<DemoItem> buildLoadingDemoItems(String codePath) {
9192
documentationUrl: '',
9293
buildRoute: (context) => BaseWidget('Loading', codePath, LoadingWidget()),
9394
),
95+
DemoItem(
96+
icon: Icons.pages,
97+
title: 'CustomProgress',
98+
subtitle: 'CustomProgress',
99+
documentationUrl: '',
100+
buildRoute: (context) => BaseWidget('CustomProgress', codePath, CustomProgressWidget()),
101+
),
94102
];
95103
}
96104

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ flutter:
325325
- lib/animation/animation/wave.dart
326326

327327
- lib/animation/loading/loading.dart
328+
- lib/animation/loading/customprogress.dart
328329

329330
- lib/animation/scrollanimation/scrollinganimation1.dart
330331
- lib/animation/scrollanimation/scrollinganimation2.dart

0 commit comments

Comments
 (0)