Repository: flutter
Issue: Tap on widgets is not detected when being clicked quickly
Labels: platform-android,platform-ios,framework,has reproducible steps,P2,team-framework,triaged-framework,found in release: 3.13,found in release: 3.14

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

1. Launch the reproducible example code provided in debug on a physical iOS device (iPad)
2. Start a screen recording
3. Quickly enter a number on the keypad (a memorized US 10-digit phone number, as an example)
4. Notice 1-2 (or more?) taps were not registered

### Expected results

Every tap callback should execute

### Actual results

1-2 keypresses are missing

### Code sample

<details><summary>Code sample</summary>

main.dart:
```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;
  final ValueKey keypadKey = const ValueKey('keypad');

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  TextEditingController pinController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also a layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Invoke "debug painting" (press "p" in the console, choose the
          // "Toggle Debug Paint" action from the Flutter Inspector in Android
          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
          // to see the wireframe for each widget.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(pinController.text),
            KeyPad(
              key: widget.keypadKey,
              onChange: updatePin,
            )
          ],
        ),
      ),
    );
  }

  updatePin(String pin, bool backspace) {
    if (backspace) {
      print('backspace');
      if (pinController.text.isNotEmpty) pinController.text = pinController.text.substring(0, pinController.text.length - 1);
    } else {
      pinController.text += pin;
      //pinController.selection = TextSelection.fromPosition(TextPosition(offset: pinController.text.length));
      //   print('${pinController.text}');
    }
    setState(() {});
  }
}

class KeyPad extends StatelessWidget {
  final double buttonSize;
  final Function onChange;
  final Function? onSubmit;
  //final bool isPinLogin;

  const KeyPad({super.key, required this.onChange, this.onSubmit, this.buttonSize = 105.0});

  @override
  Widget build(BuildContext context) {
    print('rebuilding keypad');
    return Column(
      children: [
        const SizedBox(height: 20),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            KeyPadNumberButton(key: const Key('1'), buttonText: '1', onChange: onChange),
            SizedBox(width: 20),
            KeyPadNumberButton(key: const Key('2'), buttonText: '2', onChange: onChange),
            SizedBox(width: 20),
            KeyPadNumberButton(key: const Key('3'), buttonText: '3', onChange: onChange),
          ],
        ),
        const SizedBox(height: 20),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            KeyPadNumberButton(key: const Key('4'), buttonText: '4', onChange: onChange),
            const SizedBox(width: 20),
            KeyPadNumberButton(key: const Key('5'), buttonText: '5', onChange: onChange),
            const SizedBox(width: 20),
            KeyPadNumberButton(key: const Key('6'), buttonText: '6', onChange: onChange),
          ],
        ),
        SizedBox(height: 20),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            KeyPadNumberButton(key: const Key('7'), buttonText: '7', onChange: onChange),
            SizedBox(width: 20),
            KeyPadNumberButton(key: const Key('8'), buttonText: '8', onChange: onChange),
            SizedBox(width: 20),
            KeyPadNumberButton(key: const Key('9'), buttonText: '9', onChange: onChange),
          ],
        ),
        SizedBox(height: 20),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Padding(
              padding: const EdgeInsets.only(right: 20.0),
              child: iconKeyPadNumberButton(Icons.backspace, Colors.orangeAccent, () {
                onChange!('', true);
              }),
            ),
            KeyPadNumberButton(buttonText: '0', onChange: onChange),
            Padding(
              padding: const EdgeInsets.only(left: 20.0),
              child: iconKeyPadNumberButton(Icons.check_circle, Colors.green, () {
                print('submit!');
              }),
            ),
          ],
        ),
      ],
    );
  }

  Widget iconKeyPadNumberButton(IconData icon, Color color, Function function) {
    return InkWell(
      onTap: function as void Function()?,
      child: Container(
        height: buttonSize,
        width: buttonSize,
        decoration: BoxDecoration(color: color, shape: BoxShape.rectangle),
        child: Center(
          child: Icon(
            icon,
            size: 30,
            color: Colors.white,
          ),
        ),
      ),
    );
  }
}

class KeyPadNumberButton extends StatelessWidget {
  final String buttonText;
  final double buttonSize;
  final Function onChange;
  const KeyPadNumberButton({super.key, required this.buttonText, this.buttonSize = 105.0, required this.onChange});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: buttonSize,
      width: buttonSize,
      child: ElevatedButton(
        onPressed: () {
          print('pressed button $buttonText');
          onChange(buttonText, false);
        },
        child: Center(
          child: Text(
            buttonText,
            style: const TextStyle(fontWeight: FontWeight.bold, color: Colors.white, fontSize: 30),
          ),
        ),
      ),
    );
  }
}
```

</details>


### Screenshots or Video

<details>
<summary>Screen recording shows entering 555-555-2368</summary>

How do I call the Ghostbusters when I can't even dial their number?

<details>
<summary>Screen recording: </summary>

https://github.com/flutter/flutter/assets/143011796/280d453a-46b9-4694-956a-f2a5a307dbb5
</details>

![ghostbusters](https://github.com/flutter/flutter/assets/143011796/162b696e-24f0-4a83-ba62-aea8b8092668)

</details>


### Logs

<details><summary>Logs</summary>

```console
flutter: pressed button 5
flutter: rebuilding keypad
flutter: pressed button 5
flutter: rebuilding keypad
flutter: pressed button 5
flutter: rebuilding keypad
flutter: pressed button 5
flutter: rebuilding keypad
flutter: pressed button 5
flutter: rebuilding keypad
flutter: pressed button 5
flutter: rebuilding keypad
flutter: pressed button 2
flutter: rebuilding keypad
flutter: pressed button 6
flutter: rebuilding keypad
```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
% flutter doctor -v
[✓] Flutter (Channel stable, 3.13.0, on macOS 13.5.1 22G90 darwin-arm64, locale en-US)
    • Flutter version 3.13.0 on channel stable at /Users/davidb/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision efbf63d9c6 (8 days ago), 2023-08-15 21:05:06 -0500
    • Engine revision 1ac611c64e
    • Dart version 3.1.0
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/davidb/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • ANDROID_HOME = /Users/davidb/Library/Android/sdk
    • 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.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • 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)

[✓] VS Code (version 1.78.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.64.0

[✓] VS Code (version 1.82.0-insider)
    • VS Code at /Applications/Visual Studio Code - Insiders.app/Contents
    • Flutter extension version 3.71.20230801

[✓] Connected device (3 available)
    • David’s iPad (2) (mobile) • 00008030-001225621ED3C02E • ios            • iOS 16.6 20G75
    • macOS (desktop)           • macos                     • darwin-arm64   • macOS 13.5.1 22G90 darwin-arm64
    • Chrome (web)              • chrome                    • web-javascript • Google Chrome 116.0.5845.96

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>