| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- 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<AnimatedBackground> createState() => _AnimatedBackgroundState();
- }
- class _AnimatedBackgroundState extends State<AnimatedBackground>
- 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<Color> 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,
- ),
- ),
- ),
- );
- },
- );
- }
- }
|