Learn how to add context in the initState method of the stateful widget. We want to call something using context( Material Color, ModalRoute etc) before the build method of the widget execute.
We have two options
We can call it inside the initState method
Or
We can call it inside the didChangeDependencies
Here we learn how to use context inside initState and how to use context inside the didChangeDependencies.
But for the second case didChangeDependecies method execute multiple times. We will algorithmically run only once and get the required data by using the context.
We will encounter a problem when we try to add the context in the initState. For removing that error we use Future.delayed constructor which will simulate some delaying effect of zero time and execute our context call.
Source Conde -- github.com/hus...
If you have any question. Please write in the comments!
Негізгі бет Flutter Get context in initState and didChangeDependencies Method
Пікірлер: 21