Unhandled Exception: inheritFromWidgetOfExactType(_LocalizationsScope) or inheritFromElement() was called before _ScreenState.initState() completed

前端 未结 7 1439
半阙折子戏
半阙折子戏 2021-02-18 16:46

I am calling initial method to load data from API using initState. But it is resulting me an error. Here is error:

Unhandled Exception: inheritFromWidgetOfExactT         


        
7条回答
  •  太阳男子
    2021-02-18 17:23

    There are many ways to solve this problem, override initState method:

    @override
    void initState() {
      super.initState();
      // Use any of the below code here. 
    }
    
    • Using SchedulerBinding mixin:

      SchedulerBinding.instance.addPostFrameCallback((_) {
        // Call your function
      });
      
    • Using Future class:

      Future(() {
        // Call your function
      });
      
    • Using Timer class:

      Timer(() {
        // Call your function
      });
      

提交回复
热议问题