InitState is an important part of the flutter life cycle. Similar to viewWillAppera in iOS, initState is a necessary step before the page is created.

In this step, we may need to prepare some data, which can be divided into local and network requests.

During the request, we might use the context.

If you place the context directly in initState, the context will be null, and you need to do a delayed action on the method that uses the context:

Future.delayed(Duration.zero).then((value) async {
	/// use the method with context
	xxxxxxx
});
Copy the code