Created
April 24, 2022 11:59
-
-
Save Roaa94/1e85c4e84464ae8166d8b241a874033c to your computer and use it in GitHub Desktop.
Flutter AnimatedBuilder Example (Gradient Animation)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AnimatedBuilderExample extends StatefulWidget { | |
const AnimatedBuilderExample({Key? key}) : super(key: key); | |
@override | |
_AnimatedBuilderExampleState createState() => _AnimatedBuilderExampleState(); | |
} | |
class _AnimatedBuilderExampleState extends State<AnimatedBuilderExample> | |
with SingleTickerProviderStateMixin { | |
late final AnimationController _controller; | |
@override | |
void initState() { | |
_controller = AnimationController( | |
duration: const Duration(milliseconds: 500), | |
vsync: this, | |
)..repeat(reverse: true); | |
super.initState(); | |
} | |
@override | |
void dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return AnimatedBuilder( | |
animation: _controller, | |
builder: (BuildContext context, Widget? child) { | |
return Container( | |
height: 100, | |
decoration: BoxDecoration( | |
gradient: LinearGradient( | |
colors: const [purple, pink, yellow], | |
stops: [0, _controller.value, 1], | |
), | |
borderRadius: BorderRadius.circular(15), | |
border: Border.all(color: Colors.white), | |
), | |
); | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment