Repository: flutter
Issue: [Firefox] Textfield becomes unresponsive after focusing it a certain way
Labels: a: text input,platform-web,browser: firefox,P1,customer: quake (g3),team-web,triaged-web

### Steps to reproduce

1. Open the application in Firefox.
2. Copy some text to clipboard.
3. Click on the text field.
4. Type some things to ensure it still receives keyboard inputs.
5. Hit tab until you focus the textfield again.
6. Try typing or pasting text. The widget is now unresponsive.

### Expected results

The TextField should still receive text inputs and pasted text. 

### Actual results

The TextField is no longer responsive, despite the blinking |.

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  MyApp();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Slider A11Y Demo',
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  Widget build(BuildContext context) {
    return Scaffold(appBar: AppBar(title: Text(title)), body: ParentView());
  }
}

class ParentView extends StatefulWidget {
  @override
  _ParentViewState createState() => _ParentViewState();
}

class _ParentViewState extends State<ParentView> {
  late FocusNode _focusNode;

  @override
  void initState() {
    super.initState();
    _focusNode = FocusNode(debugLabel: 'ParentView');
  }

  @override
  void dispose() {
    _focusNode.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Semantics(
      container: true,
      explicitChildNodes: true,
      label: 'Parent View',
      child: FocusTraversalGroup(
        child: Focus(
          focusNode: _focusNode,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Flexible(
                child: Card(
                  margin: EdgeInsetsDirectional.zero,
                  color: Theme.of(context).colorScheme.surface,
                  surfaceTintColor: Theme.of(context).colorScheme.surface,
                  child: Padding(
                    padding: EdgeInsetsDirectional.only(bottom: 10.0),
                    child: AnimatedContainer(
                      duration: Durations.short4,
                      constraints: BoxConstraints(maxWidth: 356.0),
                      child: AnimatedSize(
                        alignment: Alignment.topCenter,
                        duration: Durations.short4,
                        child: AnimatedSwitcher(
                          duration: Durations.short4,
                          switchInCurve: Curves.ease,
                          switchOutCurve: Curves.ease,
                          layoutBuilder: AnimatedSwitcher.defaultLayoutBuilder,
                          child: MainView(),
                        ),
                      ),
                    ),
                  ),
                ),
              ),
              Container(),
            ],
          ),
        ),
      ),
    );
  }
}

class MainView extends StatefulWidget {
  @override
  _MainViewState createState() => _MainViewState();
}

class _MainViewState extends State<MainView> {
  late TextEditingController _textController;
  late FocusNode _focusNode;
  bool _textFieldShowing = false;

  @override
  void initState() {
    super.initState();
    _textController = TextEditingController();
    _focusNode = FocusNode(debugLabel: 'MainView');
  }

  @override
  void dispose() {
    _textController.dispose();
    _focusNode.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      if (_focusNode.canRequestFocus && _textFieldShowing) {
        _focusNode.requestFocus();
      }
    });

    return Stack(
      children: <Widget>[
        Align(
          alignment: AlignmentDirectional.bottomStart,
          child:
              _textFieldShowing
                  ? TextFieldView(
                    focusNode: _focusNode,
                    textController: _textController,
                  )
                  : TextButton(
                    child: Text('Show Text Field'),
                    onPressed: () {
                      setState(() {
                        _textFieldShowing = true;
                      });
                    },
                  ),
        ),
      ],
    );
  }
}

class TextFieldView extends StatelessWidget {
  final FocusNode focusNode;
  final TextEditingController textController;

  TextFieldView({
    Key? key,
    required this.focusNode,
    required this.textController,
  }) : super(key: key);

  void onSubmitted(String prompt) {
    print('onSubmitted: $prompt');
  }

  @override
  Widget build(BuildContext context) {
    final colorScheme = Theme.of(context).colorScheme;
    final _composerBorder = OutlineInputBorder(
      borderSide: BorderSide(color: colorScheme.surfaceContainerHigh),
      borderRadius: BorderRadius.circular(30),
    );
    return Container(
      padding: EdgeInsetsDirectional.all(16.0),
      width: double.infinity,
      decoration: BoxDecoration(
        color: colorScheme.surface,
        border: Border(
          top: BorderSide(color: colorScheme.surfaceContainerHighest),
        ),
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        spacing: 16.0,
        children: [
          Row(
            children: [
              Flexible(
                child: TextField(
                  focusNode: focusNode,
                  minLines: 1,
                  maxLines: 10,
                  // keyboardType of TextInputType.text is necessary to
                  // allow submission on Enter key with multiline
                  // textfield.
                  keyboardType: TextInputType.text,
                  controller: textController,
                  onSubmitted: onSubmitted,
                  decoration: InputDecoration(
                    suffixIcon: IconButton(
                      icon: const Icon(Icons.send),
                      onPressed: () => onSubmitted(textController.text),
                      tooltip: 'Send Prompt',
                      color: colorScheme.primary,
                    ),
                    hintText: 'Enter a prompt here',
                    filled: true,
                    fillColor:
                        Theme.of(context).colorScheme.surfaceContainerHigh,
                    focusColor:
                        Theme.of(context).colorScheme.surfaceContainerHigh,
                    border: _composerBorder,
                    enabledBorder: _composerBorder,
                    contentPadding: EdgeInsetsDirectional.symmetric(
                      horizontal: 24.0,
                      vertical: 16.0,
                    ),
                  ),
                ),
              ),
            ],
          ),
          Text.rich(
            TextSpan(
              style: Theme.of(context).textTheme.bodySmall,
              children: [
                TextSpan(text: 'Disclaimer'),
                WidgetSpan(child: SizedBox(width: 4.0)),
                WidgetSpan(
                  child: TextButton(
                    onPressed: () {},
                    child: Text('Learn More'),
                  ),
                ),
              ],
            ),
            textAlign: TextAlign.center,
          ),
        ],
      ),
    );
  }
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

https://youtu.be/87kionDxZU8

</details>


### Logs

<details open><summary>Logs</summary>

```console
$ dart-dev-runner run //experimental/users/dsanagustin/flutter_sliders/web
.../dart-dev-runner run //experimental/users/dsanagustin/flutter_sliders/web
 ______   ______   _______ 
(  __  \ (  __  \ (  ____ ) Dart Dev Runner.
| (  \  )| (  \  )| (    )|
| |   ) || |   ) || (____)|  About:      http://go/dart-dev-runner
| |   | || |   | ||     __)  Contact:    http://g/ddr-users
| |   ) || |   ) || (\ (     File a bug: http://go/dart-dev-runner-bug
| (__/  )| (__/  )| ) \ \__
(______/ (______/ |/   \__/

If Target `//experimental/users/dsanagustin/flutter_sliders/web` is a `dart_browser_binary`, you can use `$ dart-dev-runner run //experimental/users/dsanagustin/flutter_sliders/web --target-rule-class=dart_browser_binary <other args>...` to skip a secondary check to gain some startup speed.
Retrieving entrypoint arguments from `//experimental/users/dsanagustin/flutter_sliders/web:_web__ddr_entrypoint_arguments`...
Analyzing //experimental/users/dsanagustin/flutter_sliders/web:_web__ddr_entrypoint_arguments...

DDR will run blaze with no additional args.

15:10:25.880 WARNING: PenEncoderService: Could not find IPv6 address for hostname <redacted>
15:10:25.884 INFO: DdrHandler: Using legacy pen encoder to encode urls.This might cause slower start of Dart DevTools.
Machine spec: cpu=48,ssd=1,cloudtop=1,mem=117.0,mem_usage=45.0,cpu_usage=1.67
15:10:26.003 INFO: DWDS: Serving DevTools at http://<redacted>:36777

For access on the same machine:

DDR is serving at: http://localhost:8080
   with config at: http://localhost:8080/$dartDevRunnerConfig

              DDC App: http://localhost:8080/experimental/users/dsanagustin/flutter_sliders/web/web/index.ddc.html
          dart2js App: http://localhost:8080/experimental/users/dsanagustin/flutter_sliders/web/web/index.html

For remote access:

DDR is serving at: http://<redacted>:8080
   with config at: http://<redacted>:8080/$dartDevRunnerConfig

              DDC App: http://<redacted>:8080/experimental/users/dsanagustin/flutter_sliders/web/web/index.ddc.html
          dart2js App: http://<redacted>:8080/experimental/users/dsanagustin/flutter_sliders/web/web/index.html

2025-01-06 15:10:26.159390 Starting daemon...2025-01-06 15:10:26.261921 Daemon started.15:10:26 Starting build, 1 target(s): //experimental/users/dsanagustin/flutter_sliders/web:web_ddr_ddr_bundleINFO: Streaming build results to: http://sponge2/0cb9633d-8006-4a00-bb78-1f225cf04b6b
INFO: Analyzed target //experimental/users/dsanagustin/flutter_sliders/web:web_ddr_ddr_bundle (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //experimental/users/dsanagustin/flutter_sliders/web:web_ddr_ddr_bundle up-to-date:
  blaze-bin/experimental/users/dsanagustin/flutter_sliders/web/web_ddr_ddr_bundle_unused_executable
INFO: Elapsed time: 0.410s, Critical Path: 0.13s, Remote (0.00% of the time): [queue: 0.00%, setup: 0.00%, process: 0.00%]
INFO: Build completed successfully, 1 total action
INFO: Streaming build results to: http://sponge2/0cb9633d-8006-4a00-bb78-1f225cf04b6b
15:10:26 Build succeeded.
dart2js mode is INITIALIZING. This may take more than one minute.
Analyzing //experimental/users/dsanagustin/flutter_sliders/web:_web__ddr_archive_arguments...

dart2js mode is READY.
15:12:25.410 INFO: DwdsInjector: Received request for entrypoint at http://b2607f8b04800100000c24f63ac1229c11f90000000000000000001.proxy.googlers.com/experimental/users/dsanagustin/flutter_sliders/web/web/web_ddc_bundle.app.bootstrap.js
15:12:25.434 INFO: Google3LoadStrategy: Detected build options for entrypoint google3:///experimental/users/dsanagustin/flutter_sliders/web/web/main.dart:
        Flutter mode: canvaskit
        DDC canary features: false
15:12:25.435 INFO: DwdsInjector: Injected debugging metadata for entrypoint at http://b2607f8b04800100000c24f63ac1229c11f90000000000000000001.proxy.googlers.com/experimental/users/dsanagustin/flutter_sliders/web/web/web_ddc_bundle.app.bootstrap.js
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[   +2 ms] ProcessManager.runSync('which java')
[   +3 ms] executing: /usr/local/buildtools/java/jdk/bin/java --version
[        ] ProcessManager.runSync('/usr/local/buildtools/java/jdk/bin/java --version')
[  +52 ms] Exit code 0 from: /usr/local/buildtools/java/jdk/bin/java --version
[        ] openjdk 23.0.1 2024-12-05
           OpenJDK Runtime Environment (build 23.0.1+-google-release-sts-703074349)
           OpenJDK 64-Bit Server VM (build 23.0.1+-google-release-sts-703074349, mixed mode, sharing)
[        ] executing: /usr/bin/adb devices -l
[        ] ProcessManager.run('/usr/bin/adb devices -l')
[        ] Gallium device polling: connecting to galliumd.
[        ] [✓] Flutter (Channel google3, on Debian GNU/Linux rodete 6.10.11-1rodete2-amd64, locale en_US.UTF-8)
[        ]     • Framework revision 81fad61209 (39 days ago), 2024-11-28T00:00:00.000
[        ]     • Engine revision d7c0bcfe7a
[        ]     • Dart version 0740ded7b9
[        ] [✓] Android toolchain - develop for Android devices (Android SDK version Stable)
[        ]     • Android SDK at google3
[        ]     • Platform Stable, build-tools Stable
[        ]     • Java binary at: /usr/local/buildtools/java/jdk/bin/java
[        ]       This JDK was found in the system PATH.
[        ]       To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
[        ]     • Java version OpenJDK Runtime Environment (build 23.0.1+-google-release-sts-703074349)
[        ] [✓] VS Code (version 1.87.1)
[        ]     • VS Code at /usr/share/code
[        ]     • Flutter extension can be installed from:
[        ]       🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[   +9 ms] List of devices attached
[   +2 ms] Gallium device polling failed to connect to galliumd: gRPC Error (code: 14, codeName: UNAVAILABLE, message: Error connecting: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = localhost, port = 37250,
details: null, rawResponse: null, trailers: {})
[        ] executing: uname -m
[        ] ProcessManager.runSync('uname -m')
[   +1 ms] Exit code 0 from: uname -m
[        ] x86_64
[        ] executing: /usr/bin/adb devices -l
[        ] ProcessManager.run('/usr/bin/adb devices -l')
[   +4 ms] List of devices attached
[        ] [✓] Connected device (1 available)
[        ]     • Linux (desktop) • linux • linux-x64 • Debian GNU/Linux rodete 6.10.11-1rodete2-amd64
[        ] [✓] Google3 (on linux)
[        ]     • KVM enabled
[        ] • No issues found!
[        ] "flutter doctor" took 77ms.
[  +60 ms] ensureAnalyticsSent: 59ms
[        ] Running 2 shutdown hooks
[        ] Shutdown hooks complete
[        ] exiting with code 0
```

</details>

# Similar Issues

#157579