What is the difference between putting the value that need to be updated inside the setState vs outside?
setState(() {
_counter++;
});
and
_counter++;
setState(() {});
What is the difference between putting the value that need to be updated inside the setState vs outside?
setState(() {
_counter++;
});
and
_counter++;
setState(() {});
assuming that you know what setState do, it is not the same but it do the same thing in your case you notify the framework that the internal state of this object has changed after changing the object internal state but if you use it as
setState(() {});
_counter++;
you might get unexpected result if your function takes a lot time the the setState wouldn't do anything
for example try this
setState(() {});
await Future.delayed(Duration(milliseconds: 500));
_counter++;
so it dependence on the function time and place(before or after setState). However it is better to put the value inside the setState to avoid unexpected behavior and it's the best practices for using setState as I know.