0
   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();
 }
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56

1 Answers1

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