1

Assume we are creating a stateful widget with a single property (or field) as follows

int counter;

I found two ways to modify the counter:

  • First approach

    counter++;
    setState((){}); // empty setState
    
  • Second approach

    setState((){counter++;}); // wrapping setState
    

Question

Either approach produces the same result. The updated counter are shown visually in a Text widget for example. I am wondering whether there are any other differences that are hard to see visually.

Second Person Shooter
  • 14,188
  • 21
  • 90
  • 165
  • I would like to make a note that I retracted the answer I just posted, as I was not aware of the subtlety that calling setState in the two ways you've mentioned are meant to be equivalent. More info: https://stackoverflow.com/questions/52383575/empty-set-state-what-is-the-point – S.V. Oct 18 '20 at 21:49
  • @DrSatan1: Thank you for the links and previous answer. I am reading... and I will decide whether it is a duplicate or not soon. – Second Person Shooter Oct 18 '20 at 21:57

0 Answers0