Skip to content

Instantly share code, notes, and snippets.

@Roaa94
Created April 24, 2022 11:59
Show Gist options
  • Save Roaa94/1e85c4e84464ae8166d8b241a874033c to your computer and use it in GitHub Desktop.
Save Roaa94/1e85c4e84464ae8166d8b241a874033c to your computer and use it in GitHub Desktop.
Flutter AnimatedBuilder Example (Gradient Animation)
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