tauhid-hasan-dev / currency_converter_app_flutter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

currency_converter

Read: https://medium.com/@hadiyaaamir222/lifecycle-of-a-stateful-widget-aece2d56c946 Watch: https://www.youtube.com/watch?v=_gIbneld-bw&ab_channel=FlutterCommunity

A new Flutter project.

// https://www.tcmb.gov.tr/kurlar/today.xml

StatefulWidget Lifecycle Overview

This guide provides a detailed overview of the lifecycle of a StatefulWidget in Flutter, from creation to disposal. Understanding these steps is crucial for effective Flutter development, particularly in managing resources and maintaining performance.

Table of Contents

1. Widget Creation

At this initial stage, the constructor of the widget is called. This is the phase where constants or final variables are initialized.

2. Initialization

The initState() method kicks in here. Set up the initial state, fetch initial data, and initialize any controllers or listeners necessary for the widget.

3. Call super.initState()

Within initState(), ensure to call super.initState() to execute the parent class's initialization procedures.

4. Perform Custom Initialization

Still in the initState(), perform any operations such as data fetching or setting up event listeners.

5. Widget Building

The build() method constructs the widget visually based on its current state. This method represents the widget in terms of simpler, often composite widgets.

6. Widget Updating

The widget updates when setState() is invoked due to events, interactions, or incoming data, causing the build() method to rerun and reflect state changes in the UI.

7. Widget Rebuilding

The widget continues to rebuild in response to state changes until it is deemed no longer needed.

8. Widget Removal

This step occurs when the widget is removed from the widget tree, such as when navigating away from a screen or it's no longer displayed by its parent.

9. Disposing

The dispose() method is called, marking the end of the widget's lifecycle. Here, clean up all resources like disposing controllers, detaching listeners, closing streams, and other necessary cleanup to prevent memory leaks.

10. Call super.dispose()

Finally, within the dispose() method, call super.dispose() to ensure that the base class's disposal mechanisms are executed.

Understanding and properly managing these lifecycle methods ensures efficient resource management and smooth user experiences in your Flutter applications.

About


Languages

Language:C++ 42.1%Language:CMake 34.3%Language:Dart 14.4%Language:HTML 3.3%Language:Swift 3.1%Language:C 2.5%Language:Kotlin 0.2%Language:Objective-C 0.1%