I am trying to replace a child StatefulWidget upon pressing a button. It works if the child is a StatelessWidget, and if the StatefulWidget doesn't actually have any state.
I'm relatively new to Flutter and I don't understand why this would happen. In my mind a new Widget (regardless of whether it is Stateless or Stateful) is instantiated with new state, the child Widget is replaced in the setState() method, and the screen should be updated to reflect this.
Can anyone explain this to me?
I have written a short example to better illustrate my issue:
https://dartpad.dev/?id=5de8c8ef70d200d75a324ab85ff5e209
In the above example I would have expected both Containers to change color upon pressing the button.