Learn the original text: https://zhuanlan.zhihu.com/p/149603388
When the button is clicked, the showtestdialog () method is executed. The interface will display a small window with a check box.
Of course, the effect we want to achieve is to change the state of the check box when the user clicks the check box. Therefore, in the onchanged () method of the check box, the method that determines the state of the check box is changedBoolean value, and setstate().
However, the real operation results are not as effective as expected.
To investigate the reason, we need to start with setstate().
As the name suggests, setstate () requires that its object must be a stateful component. If the action object itself is stateless, setstate() will not work.
Therefore, we find the reason: the subcomponents in simpledialog () are stateless by default.
The next solution is simple, just inSimpledialog componentThe external “set” can be a statefulbuilder component. Refer to the following code: