As per my inforamtion,

flutter has a widget tree and an element tree. For every stateful widget in the widget tree an element in the element tree is created with state object attached to it, that is pointing at the widget and which rebuilds the widget when we call setState(), by destroying it and replacing with a new widget.

If the widget is destroyed, then where is all the widget configuration held until new widget is replaced instead of the old one?


Solution 1: Ma Jeed

there are 3 trees : Widget Tree, Element Tree and Render Object Tree.

watch this:

How Flutter renders Widgets


Solution 2: liam spiegel

the widget is not really destroyed if you call setState

only on the screen the widgets was destroyed if you call setState