Repository: flutter
Issue: Keyboard, Linux and MacOS, dead keys, characters are wrong
Labels: a: text input,framework,platform-mac,a: internationalization,platform-linux,has reproducible steps,P2,team-framework,triaged-framework,fyi-text-input,found in release: 3.24,found in release: 3.25

### Steps to reproduce

1. Run the sample code on Linux or MacOS
2. Switch to French input method
3. Press `[`, then press `e`

### Expected results

The second event character should be `ê`, but it's not.

### Actual results

See the screenshot.


Results from https://github.com/flutter/flutter/issues/154055#issuecomment-2309898881

<details open><summary>Output logs on Linux</summary>

```console
flutter: [KeyDownEvent#45f66(physicalKey: PhysicalKeyboardKey#5b142(usbHidUsage: "0x00070053", debugName: "Num Lock"), logicalKey: LogicalKeyboardKey#f3b7b(keyId: "0x10000010a", keyLabel: "Num Lock", debugName: "Num Lock"), character: null, timeStamp: 0:17:03.718000, synthesized)]
flutter: [KeyDownEvent#45f66(physicalKey: PhysicalKeyboardKey#5b142(usbHidUsage: "0x00070053", debugName: "Num Lock"), logicalKey: LogicalKeyboardKey#f3b7b(keyId: "0x10000010a", keyLabel: "Num Lock", debugName: "Num Lock"), character: null, timeStamp: 0:17:03.718000, synthesized), KeyDownEvent#f9675(physicalKey: PhysicalKeyboardKey#f51de(usbHidUsage: "0x0007002f", debugName: "Bracket Left"), logicalKey: LogicalKeyboardKey#01bcb(keyId: "0x0000005b", keyLabel: "[", debugName: "Bracket Left"), character: null, timeStamp: 0:17:03.718000)]
flutter: [KeyDownEvent#45f66(physicalKey: PhysicalKeyboardKey#5b142(usbHidUsage: "0x00070053", debugName: "Num Lock"), logicalKey: LogicalKeyboardKey#f3b7b(keyId: "0x10000010a", keyLabel: "Num Lock", debugName: "Num Lock"), character: null, timeStamp: 0:17:03.718000, synthesized), KeyDownEvent#f9675(physicalKey: PhysicalKeyboardKey#f51de(usbHidUsage: "0x0007002f", debugName: "Bracket Left"), logicalKey: LogicalKeyboardKey#01bcb(keyId: "0x0000005b", keyLabel: "[", debugName: "Bracket Left"), character: null, timeStamp: 0:17:03.718000), KeyUpEvent#33f66(physicalKey: PhysicalKeyboardKey#f51de(usbHidUsage: "0x0007002f", debugName: "Bracket Left"), logicalKey: LogicalKeyboardKey#01bcb(keyId: "0x0000005b", keyLabel: "[", debugName: "Bracket Left"), character: null, timeStamp: 0:17:03.862000)]
flutter: [KeyDownEvent#45f66(physicalKey: PhysicalKeyboardKey#5b142(usbHidUsage: "0x00070053", debugName: "Num Lock"), logicalKey: LogicalKeyboardKey#f3b7b(keyId: "0x10000010a", keyLabel: "Num Lock", debugName: "Num Lock"), character: null, timeStamp: 0:17:03.718000, synthesized), KeyDownEvent#f9675(physicalKey: PhysicalKeyboardKey#f51de(usbHidUsage: "0x0007002f", debugName: "Bracket Left"), logicalKey: LogicalKeyboardKey#01bcb(keyId: "0x0000005b", keyLabel: "[", debugName: "Bracket Left"), character: null, timeStamp: 0:17:03.718000), KeyUpEvent#33f66(physicalKey: PhysicalKeyboardKey#f51de(usbHidUsage: "0x0007002f", debugName: "Bracket Left"), logicalKey: LogicalKeyboardKey#01bcb(keyId: "0x0000005b", keyLabel: "[", debugName: "Bracket Left"), character: null, timeStamp: 0:17:03.862000), KeyDownEvent#49e1f(physicalKey: PhysicalKeyboardKey#86a89(usbHidUsage: "0x00070008", debugName: "Key E"), logicalKey: LogicalKeyboardKey#1e0f5(keyId: "0x00000065", keyLabel: "E", debugName: "Key E"), character: "e", timeStamp: 0:17:03.981000)]
flutter: [KeyDownEvent#45f66(physicalKey: PhysicalKeyboardKey#5b142(usbHidUsage: "0x00070053", debugName: "Num Lock"), logicalKey: LogicalKeyboardKey#f3b7b(keyId: "0x10000010a", keyLabel: "Num Lock", debugName: "Num Lock"), character: null, timeStamp: 0:17:03.718000, synthesized), KeyDownEvent#f9675(physicalKey: PhysicalKeyboardKey#f51de(usbHidUsage: "0x0007002f", debugName: "Bracket Left"), logicalKey: LogicalKeyboardKey#01bcb(keyId: "0x0000005b", keyLabel: "[", debugName: "Bracket Left"), character: null, timeStamp: 0:17:03.718000), KeyUpEvent#33f66(physicalKey: PhysicalKeyboardKey#f51de(usbHidUsage: "0x0007002f", debugName: "Bracket Left"), logicalKey: LogicalKeyboardKey#01bcb(keyId: "0x0000005b", keyLabel: "[", debugName: "Bracket Left"), character: null, timeStamp: 0:17:03.862000), KeyDownEvent#49e1f(physicalKey: PhysicalKeyboardKey#86a89(usbHidUsage: "0x00070008", debugName: "Key E"), logicalKey: LogicalKeyboardKey#1e0f5(keyId: "0x00000065", keyLabel: "E", debugName: "Key E"), character: "e", timeStamp: 0:17:03.981000), KeyUpEvent#12aca(physicalKey: PhysicalKeyboardKey#86a89(usbHidUsage: "0x00070008", debugName: "Key E"), logicalKey: LogicalKeyboardKey#1e0f5(keyId: "0x00000065", keyLabel: "E", debugName: "Key E"), character: null, timeStamp: 0:17:04.154000)]
```

<details open><summary>Output logs on MacOS</summary>

```console
flutter: [KeyDownEvent#c91d2(physicalKey: PhysicalKeyboardKey#f51de(usbHidUsage: "0x0007002f", debugName: "Bracket Left"), logicalKey: LogicalKeyboardKey#01bcb(keyId: "0x0000005b", keyLabel: "[", debugName: "Bracket Left"), character: null, timeStamp: 27:28:17.865322)]
flutter: [KeyDownEvent#c91d2(physicalKey: PhysicalKeyboardKey#f51de(usbHidUsage: "0x0007002f", debugName: "Bracket Left"), logicalKey: LogicalKeyboardKey#01bcb(keyId: "0x0000005b", keyLabel: "[", debugName: "Bracket Left"), character: null, timeStamp: 27:28:17.865322), KeyUpEvent#478a8(physicalKey: PhysicalKeyboardKey#f51de(usbHidUsage: "0x0007002f", debugName: "Bracket Left"), logicalKey: LogicalKeyboardKey#01bcb(keyId: "0x0000005b", keyLabel: "[", debugName: "Bracket Left"), character: null, timeStamp: 27:28:17.966194)]
flutter: [KeyDownEvent#c91d2(physicalKey: PhysicalKeyboardKey#f51de(usbHidUsage: "0x0007002f", debugName: "Bracket Left"), logicalKey: LogicalKeyboardKey#01bcb(keyId: "0x0000005b", keyLabel: "[", debugName: "Bracket Left"), character: null, timeStamp: 27:28:17.865322), KeyUpEvent#478a8(physicalKey: PhysicalKeyboardKey#f51de(usbHidUsage: "0x0007002f", debugName: "Bracket Left"), logicalKey: LogicalKeyboardKey#01bcb(keyId: "0x0000005b", keyLabel: "[", debugName: "Bracket Left"), character: null, timeStamp: 27:28:17.966194), KeyDownEvent#4f56f(physicalKey: PhysicalKeyboardKey#86a89(usbHidUsage: "0x00070008", debugName: "Key E"), logicalKey: LogicalKeyboardKey#1e0f5(keyId: "0x00000065", keyLabel: "E", debugName: "Key E"), character: "e", timeStamp: 27:28:18.044895)]
flutter: [KeyDownEvent#c91d2(physicalKey: PhysicalKeyboardKey#f51de(usbHidUsage: "0x0007002f", debugName: "Bracket Left"), logicalKey: LogicalKeyboardKey#01bcb(keyId: "0x0000005b", keyLabel: "[", debugName: "Bracket Left"), character: null, timeStamp: 27:28:17.865322), KeyUpEvent#478a8(physicalKey: PhysicalKeyboardKey#f51de(usbHidUsage: "0x0007002f", debugName: "Bracket Left"), logicalKey: LogicalKeyboardKey#01bcb(keyId: "0x0000005b", keyLabel: "[", debugName: "Bracket Left"), character: null, timeStamp: 27:28:17.966194), KeyDownEvent#4f56f(physicalKey: PhysicalKeyboardKey#86a89(usbHidUsage: "0x00070008", debugName: "Key E"), logicalKey: LogicalKeyboardKey#1e0f5(keyId: "0x00000065", keyLabel: "E", debugName: "Key E"), character: "e", timeStamp: 27:28:18.044895), KeyUpEvent#7582e(physicalKey: PhysicalKeyboardKey#86a89(usbHidUsage: "0x00070008", debugName: "Key E"), logicalKey: LogicalKeyboardKey#1e0f5(keyId: "0x00000065", keyLabel: "E", debugName: "Key E"), character: null, timeStamp: 27:28:18.202908)]
```

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Keyboard Event Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const KeyboardEventPage(),
    );
  }
}

class KeyboardEventPage extends StatefulWidget {
  const KeyboardEventPage({super.key});

  @override
  _KeyboardEventPageState createState() => _KeyboardEventPageState();
}

class _KeyboardEventPageState extends State<KeyboardEventPage> {
  final List<String> _lastKeyEvents = [];
  final FocusNode _focusNode = FocusNode();

  @override
  Widget build(BuildContext context) {
    final child = Scaffold(
      appBar: AppBar(
        title: const Text('Keyboard Event Demo'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'Press any key:',
              style: TextStyle(fontSize: 20),
            ),
            const SizedBox(height: 20),
            for (final keyEvent in _lastKeyEvents)
              Text(
                keyEvent,
                style: const TextStyle(fontSize: 16),
              ),
          ],
        ),
      ),
    );
    return FocusScope(
      autofocus: true,
      child: Focus(
        autofocus: true,
        canRequestFocus: true,
        focusNode: _focusNode,
        onKeyEvent: (node, event) {
          setState(() {
            _lastKeyEvents.add(event.toString());
            if (_lastKeyEvents.length > 10) {
              _lastKeyEvents.removeAt(0);
            }
          });
          return KeyEventResult.handled;
        },
        child: child,
      ),
    );
  }
}
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

![image](https://github.com/user-attachments/assets/69498542-1534-42a1-99fd-cf37478ead61)

</details>


### Logs

<details open><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.24.1, on Ubuntu 22.04.4 LTS 6.8.0-40-generic,
    locale en_US.UTF-8)
    • Flutter version 3.24.1 on channel stable at
      /home/username/workspace/flutter/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5874a72aa4 (6 days ago), 2024-08-20 16:46:00 -0500
    • Engine revision c9b9d5780d
    • Dart version 3.5.1
    • DevTools version 2.37.2

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from:
      https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK
      components.
      (or visit https://flutter.dev/to/linux-android-setup for detailed
      instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 14.0.0-1ubuntu1.1
    • cmake version 3.22.1
    • ninja version 1.10.1
    • pkg-config version 0.29.2

[!] Android Studio (not installed)
    • Android Studio not found; download from
      https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/to/linux-android-setup for detailed
      instructions).

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 22.04.4 LTS
      6.8.0-40-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 128.0.6613.84

[!] Network resources
    ✗ A network error occurred while checking "https://maven.google.com/":
      Connection timed out

! Doctor found issues in 3 categories.

```

</details>