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.
I tried importing the File1.dart in File2.dart but it did not fixed it.
2
Answers
You can access it by passing the widgets controller in clearField function.
A variable with a name starting with an underscore (_) is private to its library. You can only access it in the file where it is defined.
Name the variable firstNameCtrlr, without underscore, and import the file where it is defined into the file where you want to use it.