Line data Source code
1 : import 'package:flutter/material.dart';
2 :
3 : class GlowingWidget extends StatefulWidget {
4 : final Widget child;
5 : final Color glowColor;
6 : final double minRadius;
7 : final double maxRadius;
8 : final Duration duration;
9 :
10 0 : const GlowingWidget({
11 : super.key,
12 : required this.child,
13 : required this.glowColor,
14 : required this.minRadius,
15 : required this.maxRadius,
16 : this.duration = const Duration(seconds: 2),
17 : });
18 :
19 0 : @override
20 0 : _GlowingWidgetState createState() => _GlowingWidgetState();
21 : }
22 :
23 : class _GlowingWidgetState extends State<GlowingWidget> with SingleTickerProviderStateMixin {
24 : late AnimationController _controller;
25 : late Animation<double> _radiusAnimation;
26 :
27 0 : @override
28 : void initState() {
29 0 : super.initState();
30 0 : _controller = AnimationController(
31 : vsync: this,
32 0 : duration: widget.duration,
33 : upperBound: 1.0,
34 : lowerBound: 0.0,
35 0 : )..repeat(reverse: true);
36 :
37 0 : _radiusAnimation = Tween<double>(
38 0 : begin: widget.minRadius,
39 0 : end: widget.maxRadius,
40 0 : ).animate(CurvedAnimation(
41 0 : parent: _controller,
42 : curve: Curves.easeInOut,
43 : ));
44 : }
45 :
46 0 : @override
47 : void dispose() {
48 0 : _controller.dispose();
49 0 : super.dispose();
50 : }
51 :
52 0 : @override
53 : Widget build(BuildContext context) {
54 0 : return AnimatedBuilder(
55 0 : animation: _controller,
56 0 : builder: (context, child) {
57 0 : return Container(
58 0 : decoration: BoxDecoration(
59 : shape: BoxShape.circle,
60 : color: Colors.transparent,
61 0 : boxShadow: [
62 0 : BoxShadow(
63 0 : color: widget.glowColor.withOpacity(0.6),
64 : blurRadius: 12,
65 0 : spreadRadius: _radiusAnimation.value,
66 : ),
67 : ],
68 : ),
69 0 : child: widget.child,
70 : );
71 : },
72 : );
73 : }
74 : }
|