flutter-form-builder-ecosystem / flutter-form-builder-ecosystem/flutter_form_builder

[FormBuilderTextField] Expose `FormBuilderTextFieldState` and `effectiveController`

Open
#1,132 7 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Dart
Stars
1.6k
Forks
561
PR merge metrics
No merged PRs in 30d

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:

```dart
FormBuilderTextField(
name: 'example',
decoration: InputDecoration(suffixIcon: const ClearFieldButton()),
)
```

Such a widget could implicitly find the text field's text controller by doing:

```dart
var controller = context.findAncestorStateOfType().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`:

```dart
// 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.