The only stateful widget has a 10-step life cycle.
The stateless widget doesn't have a life cycle because it can't be updated once it is created.
1. createState()
A class to inherit StatefulWidget class should call createState() function.
This function returns State class that contains other life cycle functions.
In other words, you can understand it as a function creating a state of a widget.
2. mounted -> true
mounted property is changed to true right after createState() is invoked.
3. initState()
initState() function is invoked once at the initializing the widget.
4. didChangeDependencies()
didChangeDependencies() function is invoked right after initState() is invoked.
5. build()
build() function renders widgets to screen.
6. didUpdateWidget()
didUpdateWidget() function is invoked when it needs to update widget after parent widget or data is changed.
7. setState()
setState() function notifies data is changed.
This function is needed to apply changed data to UI.
8. deactivate()
deactivate() function is invoked when the State instance is removed from the Flutter tree.
Corresponding memory isn't removed until dispose() function is invoked.
Therefore, the State instance can be reused before dispose() function is invoked.
9. dispose()
dispose() function is invoked to remove permanently.
10. mounted -> false
mounted property is changed to false after disappearing State instance.
Conclusion
The life cycle is important when you create an application.
Please understand it clearly.
'Dart (Flutter)' 카테고리의 다른 글
[Flutter] Adding Fonts to Flutter Application (0) | 2022.03.26 |
---|---|
[Flutter] Adding Image to Flutter Application (0) | 2022.03.26 |
[Dart] Data Communication with Stream (0) | 2022.03.20 |
[Dart] Handling JSON (0) | 2022.03.12 |
[Flutter] Getting Started on Android Studio (0) | 2022.02.27 |
댓글