Life cycle of flutter

Life cycle of flutter


initState(): when the widget is inserted into the widget tree for the first time, it will be called. For each state object, the fluent framework will only call the callback once. Therefore, some one-time operations are usually done in the callback, such as state initialization, subscribing to event notification of subtree, etc. Buildcontext. cannot be called in this callback Dependoninheritedwidgetofexacttype. The reason is that the inheritfromwidget in the widget tree may also change after initialization. Therefore, the correct way is to call it in the build() method or didchangedependencies().

didChangeDependencies(): called when the dependency of the state object changes; For example: an inheritedwidget was included in the previous build (), and then the inheritedwidget changed in the subsequent build (), then the didchangedependencies() callback of the child widget of the inheritedwidget will be called. A typical scenario is that when the system language locale or application theme changes, the fluent framework will notify the widget to call this callback.

build(): it is mainly used to build widget subtree and will be called in the following scenarios:

After calling initstate().
After calling didupdatewidget().
After calling setstate().
After calling didchangedependencies().
After the state object is removed from one location in the tree (deactivate is called) and reinserted into another location in the tree.
reassemble(): this callback is specially provided for development and debugging. It will be called during hot reload. This callback will never be called in release mode.

didUpdateWidget(): when the widget is rebuilt, the fluent framework will call the widget Canupdate to detect the old and new nodes at the same location in the widget tree, and then decide whether to update if the widget If canupdate returns true, this callback will be called. As mentioned earlier, widget Canupdate will return true when the key and runtimetype of the old and new widgets are equal at the same time, that is, didupdatewidget() will be called when the key and runtimetype of the old and new widgets are equal at the same time.

deactivate(): this callback is called when the state object is removed from the tree. In some scenarios, the fluent framework will reinsert the state object into the tree. For example, when the subtree containing the state object moves from one position of the tree to another (it can be realized through globalkey). If it is not reinserted into the tree after removal, then the dispose () method is called.

dispose(): called when the state object is permanently removed from the tree; Typically, resources are released in this callback.

Recommended Today

6、 Transaction index view cursor

1、 Business Personnel information is as follows: (the second column is the ID number, and the third column is the bank card number) –Liu Bei 420107198905064135 6225125478544587–Guan Yu 420107199507104133 6225547858741263–Zhang Fei 420107199602034138 6225547854125656 (1) Assuming Liu Bei withdraws 6000 (add check constraint, set account balance must be > = 0), it is required to use […]