What is the difference between didChangeDependencies and initState?

后端 未结 8 941
刺人心
刺人心 2021-01-31 17:09

I am new to flutter and when I want to call my context in InitState it throws an error : which is about BuildContext.inheritFromWidgetOfExactType but then I use did

8条回答
  •  余生分开走
    2021-01-31 17:46

    I've found a significant difference between initState and didChangeDependencies:

    • initState is called only once for a widget.
    • didChangeDependencies may be called multiple times per widget lifecycle (in my case it was called when the keyboard appears / disappears)

提交回复
热议问题