forked from toly1994328/FlutterUnit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e74e18c
commit 4d1baaf
Showing
2 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import 'dart:math'; | ||
import 'dart:ui' as ui; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
class CircleHalo extends StatefulWidget { | ||
const CircleHalo({Key key}) : super(key: key); | ||
|
||
@override | ||
_CircleHaloState createState() => _CircleHaloState(); | ||
} | ||
|
||
class _CircleHaloState extends State<CircleHalo> | ||
with SingleTickerProviderStateMixin { | ||
AnimationController _ctrl; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_ctrl = AnimationController( | ||
vsync: this, | ||
duration: Duration(seconds: 2), | ||
); | ||
_ctrl.repeat(); | ||
|
||
} | ||
|
||
@override | ||
void dispose() { | ||
_ctrl.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return CustomPaint( | ||
size: Size(200, 200), | ||
painter: CircleHaloPainter(_ctrl), | ||
); | ||
} | ||
} | ||
|
||
class CircleHaloPainter extends CustomPainter { | ||
Animation<double> animation; | ||
|
||
CircleHaloPainter(this.animation) : super(repaint: animation); | ||
|
||
final Animatable<double> rotateTween = Tween<double>(begin: 0, end: 2 * pi) | ||
.chain(CurveTween(curve: Curves.easeIn)); | ||
|
||
final Animatable<double> breatheTween = TweenSequence<double>( | ||
<TweenSequenceItem<double>>[ | ||
TweenSequenceItem<double>( | ||
tween: Tween<double>(begin: 0, end: 4), | ||
weight: 1, | ||
), | ||
TweenSequenceItem<double>( | ||
tween: Tween<double>(begin: 4, end: 0), | ||
weight: 1, | ||
), | ||
], | ||
).chain(CurveTween(curve: Curves.decelerate)); | ||
|
||
@override | ||
void paint(Canvas canvas, Size size) { | ||
canvas.translate(size.width / 2, size.height / 2); | ||
final Paint paint = Paint() | ||
..strokeWidth = 1 | ||
..style = PaintingStyle.stroke; | ||
|
||
Path circlePath = Path() | ||
..addOval(Rect.fromCenter(center: Offset(0, 0), width: 100, height: 100)); | ||
Path circlePath2 = Path() | ||
..addOval( | ||
Rect.fromCenter(center: Offset(-1, 0), width: 100, height: 100)); | ||
Path result = | ||
Path.combine(PathOperation.difference, circlePath, circlePath2); | ||
|
||
List<Color> colors = [ | ||
Color(0xFFF60C0C), | ||
Color(0xFFF3B913), | ||
Color(0xFFE7F716), | ||
Color(0xFF3DF30B), | ||
Color(0xFF0DF6EF), | ||
Color(0xFF0829FB), | ||
Color(0xFFB709F4), | ||
]; | ||
colors.addAll(colors.reversed.toList()); | ||
final List<double> pos = | ||
List.generate(colors.length, (index) => index / colors.length); | ||
|
||
paint.shader = | ||
ui.Gradient.sweep(Offset.zero, colors, pos, TileMode.clamp, 0, 2 * pi); | ||
|
||
paint.maskFilter = | ||
MaskFilter.blur(BlurStyle.solid, breatheTween.evaluate(animation)); | ||
canvas.drawPath(circlePath, paint); | ||
|
||
canvas.save(); | ||
canvas.rotate(animation.value * 2 * pi); | ||
paint | ||
..style = PaintingStyle.fill | ||
..color = Color(0xff00abf2); | ||
paint.shader=null; | ||
canvas.drawPath(result, paint); | ||
canvas.restore(); | ||
} | ||
|
||
@override | ||
bool shouldRepaint(covariant CircleHaloPainter oldDelegate) => | ||
oldDelegate.animation != animation; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters