Repository: flutter
Issue: Text field loses focus when changing Gboard language on Android
Labels: a: text input,platform-android,f: focus,has reproducible steps,P2,team-text-input,triaged-text-input,found in release: 3.22

### Steps to reproduce

On a Pixel 8 with Gboard:
1. Run the app with the provided sample code
2. Change the keyboard input language

### Expected results

The text field stays focused and the keyboard stays visible, so I can keep typing.

This is the behavior of all other apps on my phone.

### Actual results

The text field loses focus and the keyboard disappears.

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Keyboard focus"),
      ),
      body: const Center(
        child: TextField(
          autofocus: true,
        ),
      ),
    );
  }
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
Restarted application in 1,419ms.
I/ImeTracker( 9336): com.example.bug:9cc5ecb3: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager( 9336): showSoftInput() view=io.flutter.embedding.android.FlutterView{779c5cb VFED..... .F...... 0,0-1080,2337 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
I/ImeTracker( 9336): com.example.bug:6aff8d06: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager( 9336): showSoftInput() view=io.flutter.embedding.android.FlutterView{779c5cb VFED..... .F...... 0,0-1080,2337 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
I/AssistStructure( 9336): Flattened final assist data: 388 bytes, containing 1 windows, 3 views
D/InputConnectionAdaptor( 9336): The input method toggled cursor monitoring on
2
D/InsetsController( 9336): show(ime(), fromIme=true)
I/ImeTracker( 9336): com.example.bug:6aff8d06: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
I/ImeTracker( 9336): com.example.bug:9cc5ecb3: onShown
W/WindowOnBackDispatcher( 9336): sendCancelIfRunning: isInProgress=falsecallback=ImeCallback=ImeOnBackInvokedCallback@21818024 Callback=android.window.IOnBackInvokedCallback$Stub$Proxy@3ac00d1
D/InputConnectionAdaptor( 9336): The input method toggled cursor monitoring off
D/InputConnectionAdaptor( 9336): The input method toggled cursor monitoring on
D/InputConnectionAdaptor( 9336): The input method toggled cursor monitoring off
W/WindowOnBackDispatcher( 9336): sendCancelIfRunning: isInProgress=falsecallback=ImeCallback=ImeOnBackInvokedCallback@21818024 Callback=android.window.IOnBackInvokedCallback$Stub$Proxy@3ac00d1
I/ImeTracker( 9336): com.example.bug:7eab1e62: onRequestHide at ORIGIN_CLIENT_HIDE_SOFT_INPUT reason HIDE_SOFT_INPUT_BY_INSETS_API
I/ImeTracker( 9336): uid(10377):bb927647: onHidden

```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.19.6, on Arch Linux 6.8.9-arch1-1, locale en_US.UTF-8)
    • Flutter version 3.19.6 on channel stable at /home/felipe/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 54e66469a9 (3 weeks ago), 2024-04-17 13:08:03 -0700
    • Engine revision c4cd48e186
    • Dart version 3.3.4
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /home/felipe/Android/Sdk/
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /home/felipe/Applications/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = chromium

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 2022.2)
    • Android Studio at /home/felipe/Applications/android-studio
    • 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.6b802.4-9586694)

[✓] Connected device (3 available)
    • Pixel 8 (mobile) • 3A101FDJH00722 • android-arm64  • Android 14 (API 34)
    • Linux (desktop)  • linux          • linux-x64      • Arch Linux 6.8.9-arch1-1
    • Chrome (web)     • chrome         • web-javascript • Chromium 124.0.6367.118 Arch Linux

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>