Why call not empty setState()? [duplicate]
This question already has an answer here:
Why does setState take a closure?
2 answers
Why Flutter defines that we should call:
setState(() { _counter++});
instead of:
_counter++;
setState(() {});
As far as I can see in setState()
code, it doesn't use anything that's passed as a parameter anyway.
flutter
marked as duplicate by Rémi Rousselet
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 at 1:59
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Why does setState take a closure?
2 answers
Why Flutter defines that we should call:
setState(() { _counter++});
instead of:
_counter++;
setState(() {});
As far as I can see in setState()
code, it doesn't use anything that's passed as a parameter anyway.
flutter
marked as duplicate by Rémi Rousselet
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 at 1:59
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Why does setState take a closure?
2 answers
Why Flutter defines that we should call:
setState(() { _counter++});
instead of:
_counter++;
setState(() {});
As far as I can see in setState()
code, it doesn't use anything that's passed as a parameter anyway.
flutter
This question already has an answer here:
Why does setState take a closure?
2 answers
Why Flutter defines that we should call:
setState(() { _counter++});
instead of:
_counter++;
setState(() {});
As far as I can see in setState()
code, it doesn't use anything that's passed as a parameter anyway.
This question already has an answer here:
Why does setState take a closure?
2 answers
flutter
flutter
asked Nov 12 at 22:35
mFeinstein
2,17472776
2,17472776
marked as duplicate by Rémi Rousselet
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 at 1:59
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Rémi Rousselet
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 at 1:59
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The end result in release mode is the same.
But in debug you get an assert for free that checks that the callback inside setState()
does not return a Future
and it returns immediately.
But if you are sure the callback is synchronous, the result in debug is the same.
Ok, but I still don't get why to force people to pass something tosetState()
... If it was calledinvalidateState()
and before calling it we set all the necessary variables, call all the Futures we want, won't it be the same?
– mFeinstein
Nov 12 at 23:13
Well, they don't force you. It is a best practice to avoid te asynchronous problems. But since you can set it outside and it works, you can do it.
– chemamolins
Nov 12 at 23:18
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The end result in release mode is the same.
But in debug you get an assert for free that checks that the callback inside setState()
does not return a Future
and it returns immediately.
But if you are sure the callback is synchronous, the result in debug is the same.
Ok, but I still don't get why to force people to pass something tosetState()
... If it was calledinvalidateState()
and before calling it we set all the necessary variables, call all the Futures we want, won't it be the same?
– mFeinstein
Nov 12 at 23:13
Well, they don't force you. It is a best practice to avoid te asynchronous problems. But since you can set it outside and it works, you can do it.
– chemamolins
Nov 12 at 23:18
add a comment |
The end result in release mode is the same.
But in debug you get an assert for free that checks that the callback inside setState()
does not return a Future
and it returns immediately.
But if you are sure the callback is synchronous, the result in debug is the same.
Ok, but I still don't get why to force people to pass something tosetState()
... If it was calledinvalidateState()
and before calling it we set all the necessary variables, call all the Futures we want, won't it be the same?
– mFeinstein
Nov 12 at 23:13
Well, they don't force you. It is a best practice to avoid te asynchronous problems. But since you can set it outside and it works, you can do it.
– chemamolins
Nov 12 at 23:18
add a comment |
The end result in release mode is the same.
But in debug you get an assert for free that checks that the callback inside setState()
does not return a Future
and it returns immediately.
But if you are sure the callback is synchronous, the result in debug is the same.
The end result in release mode is the same.
But in debug you get an assert for free that checks that the callback inside setState()
does not return a Future
and it returns immediately.
But if you are sure the callback is synchronous, the result in debug is the same.
answered Nov 12 at 22:48
chemamolins
2,0641716
2,0641716
Ok, but I still don't get why to force people to pass something tosetState()
... If it was calledinvalidateState()
and before calling it we set all the necessary variables, call all the Futures we want, won't it be the same?
– mFeinstein
Nov 12 at 23:13
Well, they don't force you. It is a best practice to avoid te asynchronous problems. But since you can set it outside and it works, you can do it.
– chemamolins
Nov 12 at 23:18
add a comment |
Ok, but I still don't get why to force people to pass something tosetState()
... If it was calledinvalidateState()
and before calling it we set all the necessary variables, call all the Futures we want, won't it be the same?
– mFeinstein
Nov 12 at 23:13
Well, they don't force you. It is a best practice to avoid te asynchronous problems. But since you can set it outside and it works, you can do it.
– chemamolins
Nov 12 at 23:18
Ok, but I still don't get why to force people to pass something to
setState()
... If it was called invalidateState()
and before calling it we set all the necessary variables, call all the Futures we want, won't it be the same?– mFeinstein
Nov 12 at 23:13
Ok, but I still don't get why to force people to pass something to
setState()
... If it was called invalidateState()
and before calling it we set all the necessary variables, call all the Futures we want, won't it be the same?– mFeinstein
Nov 12 at 23:13
Well, they don't force you. It is a best practice to avoid te asynchronous problems. But since you can set it outside and it works, you can do it.
– chemamolins
Nov 12 at 23:18
Well, they don't force you. It is a best practice to avoid te asynchronous problems. But since you can set it outside and it works, you can do it.
– chemamolins
Nov 12 at 23:18
add a comment |