Search code examples
flutterdarttextfield

Flutter - Use contextMenuBuilder instead of toolbarOptions to disable Textfield interactions


Since the upgrade to Flutter 3.x the use of toolbarOptions has been deprecated and contextMenuBuilder was introduced, I found some documentations regarding its use but can't find any docs concerning how to use it to prevent interactions.

The question is I have some parameters set to toolbarOptions and I want to migrate those params to contextMenuBuilder but I couldn't make it so

toolbarOptions: ToolbarOptions(
    copy: false,
    cut: false,
    paste: false,
    selectAll: false,
),

I tried setting null to children but it still shows the copy/paste buttons

contextMenuBuilder: (context, editable) {
    return AdaptiveTextSelectionToolbar(
        anchors: editable.contextMenuAnchors, 
        children: null
    );
},

Solution

  • Currently, I am only using

    enableInteractiveSelection: false
    

    without adding any contextmenu to the textField