What is the difference between didChangeDependencies and initState?

后端 未结 8 949
刺人心
刺人心 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:50

    you can still use context in initState() method, its hack buts works, all you need to do is sought of delay whatever you will need to execute that has context in it like so:

     @override
      void initState() {
        Future.delayed(Duration.zero).then((_) {
          // you code with context here
        });
        super.initState();
      }
    

提交回复
热议问题