TextEditingController titleC = TextEditingController();
TextEditingController detailsC = TextEditingController();
// in dispose how can in dispose or clear my controller after submitting
@override
void dispose() {
titleC.clear();
titleC.dispose();
detailsC.clear();
detailsC.dispose();
super.dispose();
}
Asked
Active
Viewed 1,654 times
0

Md. Yeasin Sheikh
- 54,221
- 7
- 29
- 56

zeeshan tariq
- 11
- 5
-
you can just use like `detailsC.dispose();` , what is the issue you get – Md. Yeasin Sheikh Sep 28 '22 at 15:34
-
The clear() method would empty the entered string text and set its default value is empty. dispose() would discard any resources used by the object. – brook yonas Sep 28 '22 at 16:03
1 Answers
3
// for TextEditingController create:
final TextEditingController _emailController = TextEditingController();
// for TextEditingController dispose:
@override
void dispose() {
/* Discards any resources used by the object. After this is called,
the object is not in a usable state and should be discarded
(calls to addListener will throw after the object is disposed) */
_emailController.dispose();
super.dispose();
}

Dharam Budh
- 515
- 2
- 9
-
likewise i also disposed as you dispose it then what's the problem? – zeeshan tariq Sep 30 '22 at 11:02
-
The value stored in the controller will automatically release once it hits the disposal method. You don't need to worry about clearing the controller value manually. Your whole controller instance will get clean once the framework calls the disposal method. – Dharam Budh Sep 30 '22 at 12:27