Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using the variable in TextEditingController in another dart file

I am trying to use the variable name _firstNameCtrlr in another page or rather class file.
File1.dart

final _firstNameCtrlr = TextEditingController();

File2.dart

class TxtFrmFldCtrlr{
  static void clearField(){
    _firstNameCtrlr.clear();
  }
}

The reason why I am trying to separate this function is that so I could put them all in one file, however the I cannot access the variable name of TextEditingController.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried importing the File1.dart in File2.dart but it did not fixed it.

>Solution :

You can access it by passing the widgets controller in clearField function.

import 'package:flutter/cupertino.dart';

class TxtFrmFldCtrlr{
  static void clearField(TextEditingController _firstNameCtrlr){
    _firstNameCtrlr.clear();
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading