Why call not empty setState()? [duplicate]












0















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.










share|improve this question













marked as duplicate by Rémi Rousselet flutter
Users with the  flutter badge can single-handedly close flutter questions as duplicates and reopen them as needed.

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 '18 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.




















    0















    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.










    share|improve this question













    marked as duplicate by Rémi Rousselet flutter
    Users with the  flutter badge can single-handedly close flutter questions as duplicates and reopen them as needed.

    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 '18 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.


















      0












      0








      0








      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.










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 '18 at 22:35









      mFeinstein

      2,20872776




      2,20872776




      marked as duplicate by Rémi Rousselet flutter
      Users with the  flutter badge can single-handedly close flutter questions as duplicates and reopen them as needed.

      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 '18 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 flutter
      Users with the  flutter badge can single-handedly close flutter questions as duplicates and reopen them as needed.

      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 '18 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.


























          1 Answer
          1






          active

          oldest

          votes


















          2














          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.






          share|improve this answer





















          • 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 '18 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 '18 at 23:18


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          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.






          share|improve this answer





















          • 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 '18 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 '18 at 23:18
















          2














          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.






          share|improve this answer





















          • 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 '18 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 '18 at 23:18














          2












          2








          2






          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 '18 at 22:48









          chemamolins

          2,3341816




          2,3341816












          • 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 23:18



          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python