I'm trying to make a class where if you click on a button it grows, and click again shrinks back. but the animation does not work

this is what I have

import 'package:flutter/material.dart';
import 'package:flutter_button_collection/flutter_button_collection.dart';

class AnimatedShadowButton extends StatefulWidget {
  final double height;
  final double width;
  final double finalHeight;
  final double finalWidth;

  const AnimatedShadowButton(
      {Key key, this.height, this.width, this.finalHeight, this.finalWidth})
      : assert(height < finalHeight),
        assert(width < finalWidth),
        super(key: key);

  @override
  _AnimatedShadowButtonState createState() => _AnimatedShadowButtonState();
}

class _AnimatedShadowButtonState extends State<AnimatedShadowButton> {
  double buttonHeight;
  double buttonWidth;

  void aniButo() {
    setState(() {
      buttonHeight = widget.height <= widget.finalHeight
          ? widget.finalHeight
          : widget.height;
      buttonWidth =
          widget.width <= widget.finalWidth ? widget.finalWidth : widget.width;
    });
  }

  Widget build(BuildContext context) {
    return AnimatedContainer(
      duration: Duration(milliseconds: 300),
      curve: Curves.easeInBack,
      width: buttonWidth,
      height: buttonHeight,
      child: AVLButton(
        onPressed: () {
          aniButo();
        },
        child: Text("This is a text"),
        elevation: 30.0,
      ),
    );
  }
}

if I give the buttonHeight and the buttonWidth values and everything is static it works but I want to be able to use it as such

AnimatedShadowButton(
              height: 60.0,
              width: 100.0,
              finalHeight: 90.0,
              finalWidth: 150.0,
            ),


Solution 1: Andrey Turkovsky

I think you have to changeaniButo method. Like this:

void aniButo() {
  setState(() {
    buttonHeight = buttonHeight == widget.height
        ? widget.finalHeight
        : widget.height;
    buttonWidth = buttonWidth == widget.width 
        ? widget.finalWidth 
        : widget.width;
  });
}

UPD

Inside _AnimatedShadowButtonState add initState method

@override
void initState() {
  buttonHeight = widget.height
  buttonWidth = widget.width
  super.initState();
}