Skip to content

TextField contextMenuBuilder is not used when passing selectionControls on mobile #122421

@cottonman132

Description

@cottonman132

As the title says, when passing a non-null parameter to a TextField's selectionControls, the contextMenuBuilder is not used. This comes up when trying to modify the appearance of the TextField's text selection handle, done through an extension of the TextSelectionControls class; but in doing so, when passing the implementation through the selectionControls parameter, the TextField's toolbar is built from the buildToolbar method in the TextSelectionControls implementer, ignoring the contextMenuBuilder parameter.

Steps to Reproduce

  1. Execute flutter run on the code sample

Expected results: Provided contextMenuBuilder is used

Actual results: Provided contextMenuBuilder is not used

Code sample
import 'package:flutter/material.dart';

const Color darkBlue = Color.fromARGB(255, 18, 32, 47);

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
        scaffoldBackgroundColor: darkBlue,
      ),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: MyWidget(),
        ),
      ),
    );
  }
}

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return TextField(
      selectionControls: materialTextSelectionControls,
      contextMenuBuilder: (context, textState) {
        return AdaptiveTextSelectionToolbar.buttonItems(
          buttonItems: <ContextMenuButtonItem>[
            ContextMenuButtonItem(
              onPressed: () {},
              type: ContextMenuButtonType.custom,
              label: 'Example Button',
            ),
          ],
          anchors: TextSelectionToolbarAnchors(
            primaryAnchor: textState.contextMenuAnchors.primaryAnchor,
          ),
        );
      },
    );
  }
}
Details
[!] Flutter (Channel stable, 3.7.7, on macOS 12.6.3 21G419 darwin-x64, locale es-PY)
    • Flutter version 3.7.7 on channel stable at /Users/twonary/fvm/versions/3.7.7
    ! Warning: `dart` on your path resolves to /usr/local/Cellar/dart/2.19.2/libexec/bin/dart, which is
      not inside your current Flutter SDK checkout at /Users/twonary/fvm/versions/3.7.7. Consider adding
      /Users/twonary/fvm/versions/3.7.7/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2ad6cd72c0 (2 days ago), 2023-03-08 09:41:59 -0800
    • Engine revision 1837b5be5f
    • Dart version 2.19.4
    • DevTools version 2.20.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use
      "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/twonary/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
bugreport.mov

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: text inputEntering text in a text field or keyboard related problemsf: material designflutter/packages/flutter/material repository.found in release: 3.7Found to occur in 3.7found in release: 3.9Found to occur in 3.9frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions