title: Flutter: variable not updaing for widget even when surrounding it with setState()
body: <p>This is a button in an animated container to animate the changes in dimensions and color. However the button state that should change on tap is only locally changing the variable not for the whole widget.</p>
  <p>when starting the on tap the print is always &quot;idle&quot; and at the end the print is always &quot;loading&quot; as it should. but nothing changes and when tapping again the buttonState is still idle.</p>
  <p>The container in the tree:</p>
  <pre><code>                     AnimatedContainer(
                          curve: Curves.easeOutCubic,
                          duration: Duration(milliseconds: 1000),
                          height: sHeight * 0.07,
                          width: _buttonState == CustomButtonState.idle
                              ? sWidth * 0.7
                              : _buttonState == CustomButtonState.loading
                                  ? sHeight * 0.07
                                  : _buttonState == CustomButtonState.fail
                                      ? sWidth * 0.7
                                      : sWidth * 0.7,
                          padding: EdgeInsets.symmetric(
                            horizontal: sWidth * kcardHorizontalMargin,
                          ),
                          decoration: BoxDecoration(
                              color: _buttonState == CustomButtonState.idle
                                  ? Colors.grey.shade500
                                  : _buttonState == CustomButtonState.loading
                                      ? kblueColor
                                      : _buttonState == CustomButtonState.fail
                                          ? kredColor
                                          : ksecondaryColor,
                              borderRadius: BorderRadius.circular(25)),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              GestureDetector(
                                child: _buttonState == CustomButtonState.idle
                                    ? Container(
                                        child: Text(
                                          'Confirm',
                                          style: kloginButtonText.copyWith(
                                              color: ksecondaryColor),
                                        ),
                                      )
                                    : _buttonState == CustomButtonState.loading
                                        ? Container(
                                            child: CircularProgressIndicator(
                                              backgroundColor: ksecondaryColor,
                                            ),
                                          )
                                        : _buttonState == CustomButtonState.fail
                                            ? Row(
                                                mainAxisAlignment:
                                                    MainAxisAlignment
                                                        .spaceBetween,
                                                children: [
                                                  Icon(
                                                    Icons.cancel,
                                                    color: kredColor,
                                                  ),
                                                  Container(
                                                    child: Text(
                                                      'Fail',
                                                      style: kloginButtonText
                                                          .copyWith(
                                                              color:
                                                                  ksecondaryColor),
                                                    ),
                                                  ),
                                                ],
                                              )
                                            : Row(
                                                mainAxisAlignment:
                                                    MainAxisAlignment
                                                        .spaceBetween,
                                                children: [
                                                  Icon(
                                                    Icons.check,
                                                    color: ksecondaryColor,
                                                  ),
                                                  Container(
                                                    child: Text(
                                                      'Success',
                                                      style: kloginButtonText
                                                          .copyWith(
                                                              color:
                                                                  ksecondaryColor),
                                                    ),
                                                  ),
                                                ],
                                              ),
                                onTap: () {
                                  print(_buttonState);
                                  if (_buttonState == CustomButtonState.idle) {
                                    changeButtonState(
                                        CustomButtonState.loading);
                                  } else if (_buttonState ==
                                      CustomButtonState.loading) {
                                    changeButtonState(CustomButtonState.success);
                                  } else {
                                    changeButtonState(CustomButtonState.idle);
                                  }
                                  print(&quot;after ontap: $_buttonState&quot;);
                                },
                              ),
                            ],
                          ),
                        ),
  </code></pre>
  <p>The custom button state:</p>
  <pre><code>enum CustomButtonState { idle, loading, success, fail }
  </code></pre>
  <p>The changeButtonState method:</p>
  <pre><code>  CustomButtonState changeButtonState(CustomButtonState state) {
  print(&quot;changing to: $state&quot;);
  switch (state) {
    case CustomButtonState.idle:
      setState(() {
        _buttonState = CustomButtonState.idle;
      });
      break;
    case CustomButtonState.loading:
      setState(() {
        _buttonState = CustomButtonState.loading;
      });
      break;
    case CustomButtonState.fail:
      setState(() {
        _buttonState = CustomButtonState.fail;
      });
      break;
    case CustomButtonState.success:
      setState(() {
        _buttonState = CustomButtonState.success;
      });
      break;
  }
  print(&quot;changed to: $_buttonState&quot;);
  }
  </code></pre>