Skip to content

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

@justinmc

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

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