From 776e77080475df16832e42da32137383063bffa1 Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Fri, 20 Aug 2021 09:17:11 +0800 Subject: [PATCH] add animate live widget --- .fvm/flutter_sdk | 2 +- .fvm/fvm_config.json | 3 +- CHANGELOG.md | 4 ++ lib/src/animate_live_builder.dart | 67 ++++++++++++++++++++++++++++++ lib/src/animate_live_parinter.dart | 50 ++++++++++++++++++++++ lib/src/animate_live_widget.dart | 49 ++++++++++++++++++++++ pubspec.lock | 43 +++++++++++-------- pubspec.yaml | 2 +- 8 files changed, 199 insertions(+), 21 deletions(-) create mode 100644 lib/src/animate_live_builder.dart create mode 100644 lib/src/animate_live_parinter.dart create mode 100644 lib/src/animate_live_widget.dart diff --git a/.fvm/flutter_sdk b/.fvm/flutter_sdk index b01ff9a..2261e8b 120000 --- a/.fvm/flutter_sdk +++ b/.fvm/flutter_sdk @@ -1 +1 @@ -/Users/akufe/fvm/versions/2.0.0 \ No newline at end of file +/Users/zhangmeng/fvm/versions/2.0.2 \ No newline at end of file diff --git a/.fvm/fvm_config.json b/.fvm/fvm_config.json index 309af34..de7d397 100644 --- a/.fvm/fvm_config.json +++ b/.fvm/fvm_config.json @@ -1,3 +1,4 @@ { - "flutterSdkVersion": "2.0.0" + "flutterSdkVersion": "2.0.2", + "flavors": {} } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ef92ea..3d97702 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,3 +3,7 @@ ## [0.0.1] - Add AnimatedRotate * AnimatedRotate. + +## [0.0.2] -Add AnimateLiveWidget + +* AnimateLiveWidget diff --git a/lib/src/animate_live_builder.dart b/lib/src/animate_live_builder.dart new file mode 100644 index 0000000..6e45708 --- /dev/null +++ b/lib/src/animate_live_builder.dart @@ -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 + 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), + ); + }); + } +} diff --git a/lib/src/animate_live_parinter.dart b/lib/src/animate_live_parinter.dart new file mode 100644 index 0000000..77b4861 --- /dev/null +++ b/lib/src/animate_live_parinter.dart @@ -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; + } +} diff --git a/lib/src/animate_live_widget.dart b/lib/src/animate_live_widget.dart new file mode 100644 index 0000000..78060a6 --- /dev/null +++ b/lib/src/animate_live_widget.dart @@ -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 { + @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)), + ], + )); + } +} diff --git a/pubspec.lock b/pubspec.lock index 8cd6264..9384906 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,49 +5,49 @@ packages: dependency: transitive description: name: async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.0" characters: dependency: transitive description: name: characters - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.1.0" charcode: dependency: transitive description: name: charcode - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.2.0" clock: dependency: transitive description: name: clock - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.1.0" collection: dependency: transitive description: name: collection - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.15.0" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.2.0" flutter: @@ -55,6 +55,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_screenutil: + dependency: "direct main" + description: + name: flutter_screenutil + url: "https://pub.dartlang.org" + source: hosted + version: "5.0.0+2" flutter_test: dependency: "direct dev" description: flutter @@ -64,21 +71,21 @@ packages: dependency: transitive description: name: matcher - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.12.10" meta: dependency: transitive description: name: meta - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.3.0" path: dependency: transitive description: name: path - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.8.0" sky_engine: @@ -90,56 +97,56 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.2.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.2.19" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.3.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.0" sdks: diff --git a/pubspec.yaml b/pubspec.yaml index c25fe8a..57817d4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ environment: dependencies: flutter: sdk: flutter - + flutter_screenutil: ^5.0.0 dev_dependencies: flutter_test: sdk: flutter