Skip to content

It should be possible to create disabled buttons with ContextMenuButtonItem #124247

@justinmc

Description

@justinmc

For example, native iOS shows a disabled button when it finds no spell check suggestion for a word:

Screenshot 2023-04-05 at 9 26 16 AM

Flutter creates a button that looks tappable but nothing happens if you do tap it:

Screenshot 2023-04-05 at 11 18 01 AM

All of Flutter's buttons allow this kind of disabled button by passing null for onPressed. Only ContextMenuButton doesn't support this (its onPressed is uniquely non-nullable):

I propose we make it nullable so that it can be used to create disabled buttons.

Steps to reproduce

  1. Run an app on iOS with spell check enabled, such as the one below.
  2. Type a bunch of crazy text (so that it has no spell check suggestions). Longer is better.
  3. Tap the misspelled word.

Expected: The "No replacements found" button looks disabled, like native.
Actual: It is tappable but does nothing.

Example app
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            CupertinoTextField(
              maxLines: 4,
              spellCheckConfiguration: SpellCheckConfiguration(
                spellCheckService: DefaultSpellCheckService(),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Metadata

Metadata

Assignees

Labels

a: text inputEntering text in a text field or keyboard related problems

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions