Importance of Calling SetState inside initState

前端 未结 2 1297
忘了有多久
忘了有多久 2020-11-30 08:06

Should setState() method be called inside initState() method of a StatefullWidget?

My understanding is that initState()<

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 08:36

    You don't need to use setState within initState. In fact, it will not work if you do so.

    The thing is, you are not calling setState within initState in your example.

    What you do is calling setState on an asynchronous event. But since it's asynchronous, the initState method has already finished

提交回复
热议问题