import 'package:flutter/material.dart'; import 'dart:math' as math; import '../../utils/colors.dart'; class AnimatedBackground extends StatefulWidget { final Widget child; final bool isZenMode; const AnimatedBackground({ super.key, required this.child, this.isZenMode = false, }); @override State createState() => _AnimatedBackgroundState(); } class _AnimatedBackgroundState extends State with TickerProviderStateMixin { late AnimationController _controller1; late AnimationController _controller2; late AnimationController _controller3; @override void initState() { super.initState(); // Create multiple animation controllers for layered effects _controller1 = AnimationController( duration: const Duration(seconds: 8), vsync: this, )..repeat(); _controller2 = AnimationController( duration: const Duration(seconds: 12), vsync: this, )..repeat(); _controller3 = AnimationController( duration: const Duration(seconds: 15), vsync: this, )..repeat(); } @override void dispose() { _controller1.dispose(); _controller2.dispose(); _controller3.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Stack( children: [ // Base background Container( decoration: const BoxDecoration( gradient: LinearGradient( begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [ ZenColors.appBackground, Color(0xFF0A0A0A), ], ), ), ), // Animated gradient layers ...List.generate(3, (index) => _buildAnimatedLayer(index)), // Content overlay widget.child, ], ); } Widget _buildAnimatedLayer(int layerIndex) { AnimationController controller; List colors; switch (layerIndex) { case 0: controller = _controller1; colors = widget.isZenMode ? [ZenColors.navyBlue.withValues(alpha: 0.3), Colors.transparent] : [ZenColors.uiElements.withValues(alpha: 0.2), Colors.transparent]; break; case 1: controller = _controller2; colors = [ZenColors.red.withValues(alpha: 0.1), Colors.transparent]; break; default: controller = _controller3; colors = [ZenColors.buttonBackground.withValues(alpha: 0.05), Colors.transparent]; } return AnimatedBuilder( animation: controller, builder: (context, child) { return Transform.rotate( angle: controller.value * 2 * math.pi, child: Container( decoration: BoxDecoration( gradient: RadialGradient( center: Alignment( math.sin(controller.value * 2 * math.pi) * 0.5, math.cos(controller.value * 2 * math.pi) * 0.5, ), radius: 1.5 + math.sin(controller.value * math.pi) * 0.5, colors: colors, ), ), ), ); }, ); } }