Copy-Paste Interaction Not Working in FormBuilderTextField

159 views Asked by At

I'm facing an issue with the FormBuilderTextField widget in Flutter. I want to enable copy-paste interaction within the FormBuilderTextField when I long-press it, but it doesn't seem to work as expected. Here's my code:

FormBuilderTextField(
  name: 'pincode',
  style: const TextStyle(
    color: primaryColor,
    fontSize: 12,
    fontWeight: FontWeight.w400,
  ),
  onChanged: (value) {},
  maxLength: 6,
  decoration: InputDecoration(
    contentPadding: const EdgeInsets.only(left: 12),
    counterText: "",
    border: buildBorderDecoration(),
    enabledBorder: buildEnableAndDisabledBorder(),
    errorBorder: buildErrorBorder(),
    disabledBorder: buildEnableAndDisabledBorder(),
    floatingLabelBehavior: FloatingLabelBehavior.never,
    fillColor: Colors.white,
    filled: true,
    labelText: '680024',
    labelStyle: const TextStyle(
      color: lightGrey,
      fontSize: 12,
      fontWeight: FontWeight.w400,
    ),
  ),
),

Despite setting enableInteractiveSelection to true, the copy-paste interaction is not working. Any suggestions on how to resolve this issue would be greatly appreciated.

  • Flutter version: 3.10.2

  • Operating System: Windows

  • Any other relevant details or code snippets.

Please let me know if you have any insights or solutions to this problem. Thank you

2

There are 2 answers

2
Vexolio On

It would seem this issue was known already.

Refer to this github link with the potential solution which is to add contextMenuBuilder to FormBuilderTextField.

FormBuilderTextField(
  name: "description",
  contextMenuBuilder: (context, editableTextState) {
    return AdaptiveTextSelectionToolbar.editableText(
        editableTextState: editableTextState,
    );
 }, 
);
0
Arjun Ranjith On

Issue Solved:

It appears that I have wrapped a Listener widget around the Scaffold beneath the MaterialApp, intending to manage keyboard unfocusing. However, this setup is causing an issue. When I attempt to paste something into a text field, the keyboard unfocus function is executed prematurely, resulting in the loss of context for the active field. This sequence disrupts the intended paste functionality, making it challenging to interact seamlessly with the text fields.

Listener(
          onPointerDown: (_){
            FocusManager.instance.primaryFocus?.unfocus();
          },
          child: ScaffoldMessenger(
            key: _scaffoldMessengerKey,
            child: Scaffold(
              resizeToAvoidBottomInset: ref.watch(avoidBottomInsetProvider),
              body: child,
            ),
          ),
        );

So I removed the Listener on top of the Scaffold and added onTapOutside to FormbuilderTextField.

onTapOutside: (event)=>FocusManager.instance.primaryFocus?.unfocus(),