Do stateless widgets dispose on their own?

前端 未结 1 457
梦谈多话
梦谈多话 2021-02-19 00:33

I created a PostUpdaterWidget extending StatelessWidget which makes use of TextEditingControllers for testing out implementation of Bloc P

相关标签:
1条回答
  • 2021-02-19 01:00

    This question seems to indicate that objects are not disposed when the StatelessWidget gets destroyed, at least not immediately. In any case, when you are using a TextEditingController (or maintaining any mutable state), then you should use a StatefulWidget and keep the state in the State class. The State class has a dispose() method that you can use (as you mentioned in your question).

    Otherwise, if you use a StatelessWidget, you lose your state every time the UI gets rebuilt. StatefulWidgets keep their state across rebuilds because the state is in the State class, not in the widget. See also this answer.

    0 讨论(0)
提交回复
热议问题