import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class AnimatedBackground extends StatefulWidget { const AnimatedBackground({super.key}); @override State createState() => _AnimatedBackgroundState(); } class _AnimatedBackgroundState extends State with SingleTickerProviderStateMixin { late AnimationController _controller; late Animation _topAnimationAlignment; late Animation _bottomAnimationAlignment; @override void initState(){ super.initState(); SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(statusBarColor: Colors.transparent,statusBarIconBrightness: Brightness.dark,)); _controller= AnimationController(vsync: this, duration: Duration(seconds: 5)); _topAnimationAlignment =TweenSequence( [ TweenSequenceItem (tween: Tween(begin: Alignment.topLeft,end: Alignment.topRight), weight: 1), TweenSequenceItem (tween: Tween(begin: Alignment.topRight,end: Alignment.bottomRight), weight: 2), TweenSequenceItem (tween: Tween(begin: Alignment.bottomRight,end: Alignment.bottomLeft), weight: 1), TweenSequenceItem (tween: Tween(begin: Alignment.bottomLeft,end: Alignment.topLeft), weight: 2), ] ).animate(_controller); _bottomAnimationAlignment =TweenSequence( [ TweenSequenceItem (tween: Tween(begin: Alignment.bottomRight,end: Alignment.bottomLeft), weight: 1), TweenSequenceItem (tween: Tween(begin: Alignment.bottomLeft,end: Alignment.topLeft), weight: 2), TweenSequenceItem (tween: Tween(begin: Alignment.topLeft,end: Alignment.topRight), weight: 1), TweenSequenceItem (tween: Tween(begin: Alignment.topRight,end: Alignment.bottomRight), weight: 2), ] ).animate(_controller); _controller.repeat(); } @override Widget build(BuildContext context) { Size screenSize =MediaQuery.of(context).size; return Scaffold( body: AnimatedBuilder( animation: _controller, builder: (context,widget){ return Container( height: screenSize.height, width: screenSize.width, decoration: BoxDecoration( gradient: LinearGradient( begin: _topAnimationAlignment.value, end: _bottomAnimationAlignment.value, colors: [ Colors.cyan.shade300, Colors.cyan.shade800, ] ) ), ); }, ) ); } }