Repository: flutter
Issue: TextField Using emoji applications on the desktop crashes, and the performance of Windows and macOS is the same
Labels: a: text input,c: crash,platform-mac,platform-windows,platform-linux,a: desktop,has reproducible steps,P2,c: fatal crash,team-text-input,triaged-text-input,found in release: 3.24,found in release: 3.25

### Steps to reproduce


1. TextField: Input content normally and then press the add button to add emojis to the text
2. TextField uses _focusNode. requestFocus(); Get the focus, then TextCelection. collaged() changes the cursor position,
3. The application crashes when typing again

1.TextField 正常输入内容然后按添加按钮在文本中加入emoji
2,TextField 使用_focusNode.requestFocus();获取焦点,然后 TextSelection.collapsed()改变光标位置
3, 再次输入时应用程序崩溃


### Expected results


TextField cursor position changes, application runs normally
TextField光标位置改变， 应用程序正常运行

### Actual results

The application crashed
应用程序闪退了

### Code sample

<details open><summary>Code sample</summary>

```dart
Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextField(
              focusNode: _focusNode,
              controller: _contaoller,
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          final text = _contaoller.text;
          final selection = _contaoller.selection;
          final characters = text.characters.toList();
          final safeStart = selection.start.clamp(0, characters.length);
          final safeEnd = selection.end.clamp(0, characters.length);
          const characterToInsert = '😩';
          // 
          final characterToInsert1 = characterToInsert.characters;
          
          characters.replaceRange(safeStart, safeEnd, characterToInsert1);

          final newText = characters.join();

          _contaoller.text = newText;
          _focusNode.requestFocus();
          _contaoller.selection = TextSelection.collapsed(
              offset: safeStart + characterToInsert.length);
        },
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>


[flutter-issue.webm](https://github.com/user-attachments/assets/1d63b117-95db-433d-94aa-8055fe83bd08)

</details>



### Logs

<details open><summary>Logs</summary>

```console
CLIENT ERROR: TUINSRemoteViewController does not override -viewServiceDidTerminateWithError: and thus cannot react to catastrophic errors beyond logging them
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
✓] Flutter (Channel stable, 3.24.0, on macOS 14.6.1 23G93 darwin-arm64, locale zh-Hans-CN)
    • Flutter version 3.24.0 on channel stable at /Users/zhaofeixiang/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 80c2e84975 (4 weeks ago), 2024-07-30 23:06:49 +0700
    • Engine revision b8800d88be
    • Dart version 3.5.0
    • DevTools version 2.37.2

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/zhaofeixiang/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/zhaofeixiang/Library
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1)
    • 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 17.0.11+0-17.0.11b1207.24-11852314)

[✓] VS Code (version 1.92.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.94.0

[✓] Connected device (3 available)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 14.6.1 23G93 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 14.6.1 23G93 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 127.0.6533.120

```

</details>