Reputation: 1321
How can I make a widget in flutter to constantly grow and shrink in size so that user can recognize that that is some sort of button that he or she can press ?
Upvotes: 2
Views: 429
Reputation: 7686
Having a StatefulWidget, this one is an easy way to do it:
var height = 100.0;
var width = 100.0;
@override
void initState() {
super.initState();
_animation();
}
void _animation() {
Timer.periodic(Duration(seconds: 1), (timer) {
setState(() {
height = height == 100.0 ? 50.0 : 100.0;
width = width == 100.0 ? 50.0 : 100.0;
});
});
}
@override
Widget build(BuildContext context) {
return Material(
child: Center(
child: AnimatedContainer(
duration: Duration(seconds: 1),
height: height,
width: width,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(50)
),
),
),
);
}
The result for this code is the following:
Upvotes: 5