I'm using StatelessWidget in my code now. I have TextEditingController in build method of StatelessWidget and I want to add dispose method to dispose it. However, the dispose method is only available in StatefulWidget. Do you suggest me to change StatelessWidget to StatefulWidget?
My code:
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
final TextEditingController controller = TextEditingController();
return Scaffold(
body: Center(
child: TextField(controller: controller),
),
);
}
}
I referred to this question, but it doesn't answer my question, because its question is whether StatelessWidget will does it by itself.
Feel free to leave a comment if you need more information.
Which should I use, StatelessWidget or StatefulWidget? I would appreciate any help. Thank you in advance!