I find flutter_form_builder 3.7.3
https://pub.dev/packages/flutter_form_builderreally helpful to reduce the amount of effort to build a form.
However, I'm trying to implement clearing a field in the form, for example, when the field is in focus, or with some simple means equivalent, such as long-press gesture, etc.
it's possible, as long as I have access to the field's controller.
class ExampleWidget extends StatefulWidget {
@override
_ExampleWidgetState createState() => _ExampleWidgetState();
}
class _ExampleWidgetState extends State<ExampleWidget> {
FocusNode _focusNode;
TextEditingController _textFieldController;
@override
void initState() {
_focusNode = FocusNode();
_focusNode.addListener(() {
if (_focusNode.hasFocus) _textFieldController.clear();
});
super.initState();
}
@override
Widget build(BuildContext context) => TextFormField(focusNode: _focusNode, controller: _textFieldController, ...);
}
But the question is how to get access to the controller of a field with flutter_form_builder?
I guess flutter_form_builder might have its own way of achieving the same.
If you know how to do it, please let me know.
Thanks!
Yu (Aaron)
J'ecrite, donc je pense.
Je pense, donc je suis.