Skip to content

When using TextFieldTags, sometimes pressing backspace does not remove characters from the input field as expected. This causes a frustrating user experience because users can’t delete text properly before submitting a tag. #93

@ashutoshgaur0809

Description

@ashutoshgaur0809

Cause:
This usually happens because the KeyboardListener or internal focus handling conflicts with the default behavior of the text field, especially when managing tags dynamically. Sometimes the event is intercepted and the text field doesn’t get the backspace event properly.

Fix Suggestion:

Ensure the backspace event only removes the last tag when the input is empty, otherwise let the text field handle character deletion normally.

Use RawKeyboardListener or KeyboardListener carefully — only intercept the event when the text is empty and tags are present.

Explicitly call setState or update the controller after tag removal to reflect changes immediately.

Double-check the focus node and controller are properly assigned and synchronized.

KeyboardListener(
focusNode: inputFieldValues.focusNode,
onKeyEvent: (event) {
if (event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.backspace) {
final text = inputFieldValues.textEditingController.text;
if (text.isEmpty && inputFieldValues.tags.isNotEmpty) {
// Remove last tag only when text field is empty
inputFieldValues.onTagRemoved(inputFieldValues.tags.last);
} else {
// Let TextField handle the backspace normally
}
}
},
child: /* your Wrap or widget here */,
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions