Line data Source code
1 : import 'package:flutter/material.dart'; 2 : import 'package:pal/src/theme.dart'; 3 : 4 : /* Controller class */ 5 : class PulsingCircleWidget extends StatefulWidget { 6 : final bool active; 7 : final bool done; 8 : 9 2 : const PulsingCircleWidget({Key key, this.active, this.done}) 10 2 : : super(key: key); 11 : 12 2 : @override 13 2 : _PulsingCircleWidgetState createState() => _PulsingCircleWidgetState(); 14 : } 15 : 16 : class _PulsingCircleWidgetState extends State<PulsingCircleWidget> 17 : with SingleTickerProviderStateMixin { 18 : // CORE ATTRIBUTES 19 : AnimationController controller; 20 : Animation animation; 21 : 22 2 : @override 23 : void initState() { 24 : // INITIALIZING PULSING ANIMATION 25 2 : this.controller = 26 4 : AnimationController(vsync: this, duration: Duration(milliseconds: 500)); 27 : // THE ACTIVE CIRCLE IS PULSATING BEETWEEN 8-12 OF RADIUS (16-24) 28 8 : this.animation = Tween<double>(begin: 8, end: 12).animate(this.controller); 29 : // REPEATS INFINIT 30 4 : this.controller.repeat(reverse: true); 31 2 : super.initState(); 32 : } 33 : 34 2 : @override 35 : void dispose() { 36 4 : this.controller.stop(); 37 4 : this.controller.dispose(); 38 2 : super.dispose(); 39 : } 40 : 41 2 : @override 42 : Widget build(BuildContext context) { 43 2 : return AnimatedBuilder( 44 2 : animation: this.controller, 45 4 : builder: (context, child) => CircleRender( 46 : // COLOR BASED ON IF THE CIRCLE IS DONE / ACTIVE / NONE 47 : // IN THE ORDER BELOW : DARK / CYAN / GREY 48 4 : color: widget.done 49 3 : ? PalTheme.of(context).colors.dark 50 4 : : widget.active 51 6 : ? PalTheme.of(context).colors.color3 52 2 : : Color(0xFFC1BFD6), 53 : // IF THE CIRCLE IS ACTIVE : ANIMATED / IF NOT : STATIC 54 8 : radius: widget.active ? this.animation.value : 8, 55 : ), 56 : ); 57 : } 58 : } 59 : 60 : /* Render class */ 61 : class CircleRender extends StatelessWidget { 62 : final Color color; 63 : final double radius; 64 : 65 4 : const CircleRender({Key key, this.color, this.radius}) : super(key: key); 66 : 67 2 : @override 68 : Widget build(BuildContext context) { 69 6 : return CircleAvatar(backgroundColor: this.color, radius: this.radius); 70 : } 71 : }