kamranbekirovyz
kamranbekirovyz

Reputation: 1321

How to make a widget that is constantly growing and shrinking in Flutter?

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

Answers (1)

Mariano Zorrilla
Mariano Zorrilla

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:

enter image description here

Upvotes: 5

Related Questions