Description
Environment
Package version: 7.7.0
Description
What you'd like to happen: it would be occasionally handy to have access to the FormBuilderTextFieldState
class, and effectiveController
.
For example, I'd like to create a ClearFieldButton
widget that shows a button for clearing the text field only when it's not empty. The ideal API (for ergonomics and practicality) would be:
FormBuilderTextField(
name: 'example',
decoration: InputDecoration(suffixIcon: const ClearFieldButton()),
)
Such a widget could implicitly find the text field's text controller by doing:
var controller = context.findAncestorStateOfType<FormBuilderTextFieldState>().effectiveController;
Unfortunately, though, both _FormBuilderTextFieldState
and _effectiveController
are currently private.
Alternatives you've considered: since FormBuilderTextField
has a controller
parameter, having a clear button is achievable by handling one's own TextEditingController
:
// Not pictured: instantiating and disposing _controller
FormBuilderTextField(
name: 'example',
controller: _controller,
decoration: InputDecoration(
suffixIcon: ClearFieldButton(controller: _controller),
),
)
This is significantly more cumbersome, though, especially for larger forms, where flutter_form_builder
usually excels.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status