Repository: flutter
Issue: [Web] After being inserted, text in TextField is automatically selected
Labels: a: text input,framework,platform-web,has reproducible steps,P2,team-web,triaged-web,found in release: 3.13,found in release: 3.16

### 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. Clone and run this repo: https://github.com/GP4cK/text_selection_issue
2. Tap the button "Tap me to insert text"

### Expected results

It should insert "inserted" in the text field and move the cursor to the end.

### Actual results

On Desktop it works fine.
On Web though, the text is inserted but it's selected.

### Code sample

<details><summary>Code sample</summary>

Pay attention to the line with the comment `// This should move the cursor at the end of the text, without selecting it.`

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  void onOpenDialog(BuildContext context) {
    showDialog(
        context: context,
        builder: (_) {
          return const AlertDialog(
            content: TextFieldAndButton(),
          );
        });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: Scaffold(
        appBar: AppBar(title: const Text('Demo')),
        body: const Center(child: TextFieldAndButton()),
        floatingActionButton: Builder(builder: (context) {
          return FloatingActionButton(onPressed: () => onOpenDialog(context));
        }),
      ),
    );
  }
}

class TextFieldAndButton extends StatefulWidget {
  const TextFieldAndButton({super.key});

  @override
  State<TextFieldAndButton> createState() => _TextFieldAndButtonState();
}

class _TextFieldAndButtonState extends State<TextFieldAndButton> {
  final controller = TextEditingController();
  final focusNode = FocusNode();
  @override
  void dispose() {
    controller.dispose();
    focusNode.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          TextField(
            focusNode: focusNode,
            controller: controller,
            decoration: const InputDecoration(
              hintText: 'Tap the button',
            ),
          ),
          const SizedBox(height: 16),
          ElevatedButton(
            child: const Text('Tap me to insert text'),
            onPressed: () {
              final newText = '${controller.text} inserted';
              controller.value = controller.value.copyWith(
                text: newText,
                // This should move the cursor at the end of the text, without selecting it.
                selection: TextSelection.collapsed(
                  offset: newText.length,
                ),
              );
              focusNode.requestFocus();
            },
          )
        ],
      ),
    );
  }
}

```

</details>


### Screenshots or Video

<details>
<summary>Video with Desktop on the right and Web on the left</summary>

https://github.com/flutter/flutter/assets/2680243/7e009d34-9af6-4e9f-8b92-ea2184914792


</details>


### Logs

_No response_

### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.13.7, on macOS 13.4.1 22F770820d darwin-x64, locale en-GB)
    • Flutter version 3.13.7 on channel stable at /Users/gautier/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2f708eb839 (3 weeks ago), 2023-10-09 09:58:08 -0500
    • Engine revision a794cf2681
    • Dart version 3.1.3
    • DevTools version 2.25.0

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/gautier/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.13.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • 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.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.83.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.74.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 13.4.1 22F770820d darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 118.0.5993.117

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.
```

</details>