parent
d724abf915
commit
776e770804
@ -1 +1 @@
|
||||
/Users/akufe/fvm/versions/2.0.0
|
||||
/Users/zhangmeng/fvm/versions/2.0.2
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
"flutterSdkVersion": "2.0.0"
|
||||
"flutterSdkVersion": "2.0.2",
|
||||
"flavors": {}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
import 'package:animated_collection/src/animate_live_parinter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LiveAnimate extends StatefulWidget {
|
||||
final double size;
|
||||
final double strokeWidth;
|
||||
final int place;
|
||||
final Duration delay;
|
||||
final Duration duration;
|
||||
|
||||
const LiveAnimate(
|
||||
{Key? key,
|
||||
required this.size,
|
||||
required this.strokeWidth,
|
||||
required this.place,
|
||||
required this.delay,
|
||||
required this.duration})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_LiveAnimateState createState() => _LiveAnimateState();
|
||||
}
|
||||
|
||||
class _LiveAnimateState extends State<LiveAnimate>
|
||||
with TickerProviderStateMixin {
|
||||
late AnimationController _controller;
|
||||
late Animation _animation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_controller = AnimationController(vsync: this, duration: widget.duration)
|
||||
..addStatusListener((status) {
|
||||
if (status == AnimationStatus.completed) {
|
||||
_controller.reverse();
|
||||
}
|
||||
})
|
||||
..addStatusListener((status) {
|
||||
if (status == AnimationStatus.dismissed) {
|
||||
_controller.forward();
|
||||
}
|
||||
});
|
||||
_animation = CurveTween(curve: Curves.easeInOut).animate(_controller);
|
||||
Future.delayed(widget.delay, () async {
|
||||
await _controller.forward();
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _animation,
|
||||
builder: (context, child) {
|
||||
return CustomPaint(
|
||||
painter: LiveAnimateIcon(
|
||||
_animation.value, widget.strokeWidth, widget.place),
|
||||
size: Size(widget.size / 3, widget.size * 0.5),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LiveAnimateIcon extends CustomPainter {
|
||||
final double strokeWidth;
|
||||
final double value;
|
||||
final int palce;
|
||||
|
||||
LiveAnimateIcon(
|
||||
this.value,
|
||||
this.strokeWidth,
|
||||
this.palce,
|
||||
);
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
double offset = size.height * (value * 0.3 + 0.2);
|
||||
Paint paint = Paint()
|
||||
..strokeWidth = this.strokeWidth
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeCap = StrokeCap.round
|
||||
..color = Colors.white;
|
||||
Path path = Path();
|
||||
path.moveTo(
|
||||
this.palce == 0
|
||||
? size.width * 0.8
|
||||
: this.palce == 2
|
||||
? size.width * 0.2
|
||||
: size.width / 2,
|
||||
offset);
|
||||
path.lineTo(
|
||||
this.palce == 0
|
||||
? size.width * 0.8
|
||||
: this.palce == 2
|
||||
? size.width * 0.2
|
||||
: size.width / 2,
|
||||
size.height - offset);
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant CustomPainter oldDelegate) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRebuildSemantics(covariant CustomPainter oldDelegate) {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
import 'package:animated_collection/src/animate_live_builder.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
class LiveAnimateWidget extends StatefulWidget {
|
||||
final double? size;
|
||||
final double? strokeWidth;
|
||||
|
||||
const LiveAnimateWidget({Key? key, this.size, this.strokeWidth})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_LiveAnimateWidgetState createState() => _LiveAnimateWidgetState();
|
||||
}
|
||||
|
||||
class _LiveAnimateWidgetState extends State<LiveAnimateWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: widget.size ?? 50.w,
|
||||
height: widget.size ?? 50.w,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular((widget.size ?? 50.w) / 2),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
LiveAnimate(
|
||||
size: widget.size ?? 50.w,
|
||||
duration: Duration(milliseconds: 800),
|
||||
strokeWidth: widget.strokeWidth ?? 5.w,
|
||||
place: 0,
|
||||
delay: Duration(milliseconds: 0)),
|
||||
LiveAnimate(
|
||||
size: widget.size ?? 50.w,
|
||||
duration: Duration(milliseconds: 800),
|
||||
strokeWidth: widget.strokeWidth ?? 5.w,
|
||||
place: 1,
|
||||
delay: Duration(milliseconds: 200)),
|
||||
LiveAnimate(
|
||||
size: widget.size ?? 50.w,
|
||||
duration: Duration(milliseconds: 800),
|
||||
strokeWidth: widget.strokeWidth ?? 5.w,
|
||||
place: 2,
|
||||
delay: Duration(milliseconds: 400)),
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
Loading…
Reference in new issue