Skip to content

Desktop's right click menu doesn't work outside of text fields #98272

Description

@justinmc

On our desktop platforms Mac, Linux, and Windows, right clicking anywhere in a native app usually brings up the context menu with some relevant options (Select All, etc.). In Flutter desktop apps, that menu can only be shown inside of an EditableText. Even if a developer wanted to add custom support for that menu to be shown somewhere, it would be very hacky due to tight coupling with EditableText. Soon, selection will be supported outside of EditableText (#95226), and this will be even more needed.

We should provide a simple public API for showing/hiding this menu and modifying its appearance, and we should refactor EditableText to consume that API.

To reproduce

  1. Run an app with some text field that doesn't take up the entire screen (example below).
  2. Right click on the text field and notice that the menu is shown.
  3. Click anywhere to dismiss the menu.
  4. Right click anywhere outside of the text field.
  5. No context menu is shown, and there is no way for the developer to show it if they wanted to.
Code
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter Demo'),
        ),
        body: const Center(
          child: TextField(),
        ),
      ),
    );
  }
}

Related:
#74255
#90563

Activity

  1. added
    a: text inputEntering text in a text field or keyboard related problems
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Feb 11, 2022
  2. self-assigned this
    on Feb 11, 2022
  3. added
    c: new featureNothing broken; request for a new capability
    P3Issues that are less important to the Flutter project
    on Feb 17, 2022
  4. justinmc commented on Apr 7, 2022

    @justinmc
    ContributorAuthor

    Here's a design doc that will enable context menus anywhere.

  5. justinmc commented on Oct 28, 2022

    @justinmc
    ContributorAuthor

    Here is an example of how to do this. Further examples will be added in the flutter/samples repo.

  6. github-actions commented on Nov 11, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  7. locked as resolved and limited conversation to collaborators on Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3Issues that are less important to the Flutter projecta: desktopRunning on desktopa: text inputEntering text in a text field or keyboard related problemsc: new featureNothing broken; request for a new capabilityframeworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions