Repository: flutter
Issue: WebViewWidget steals keyboard focus from a TextField on touch
Labels: a: text input,platform-android,p: webview,package,p: webview-keyboard,has reproducible steps,P2,team-android,triaged-android,fyi-text-input,found in release: 3.24,found in release: 3.27

### Steps to reproduce

1. Have a screen with a `WebViewWidget` (non-empty) and a `TextField`.
2. Focus the text field and type something. It works.
3. Tap the web view. The text field still has the focus, but the tapping the keys does nothing, and also autocomplete is gone.

I tried wrapping the web view in `ExcludeFocus` and `TextFieldTapRegion`, and adding an `onTapOutside` listener to the text field. Nothing changed this behaviour.

I am testing on Android 14 phone, Sony Xperia 10 IV.

### Expected results

I expect tapping the non-interactive web view to have no effect on the textfield.

### Actual results

When tapping on the web view, the autocomplete bar is hidden, but the keyboard stays visible, and there's a blinking cursor inside the text field. Tapping any of the keyboard keys does not work.

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class TestFocusPage extends StatefulWidget {
  const TestFocusPage({super.key});

  @override
  State<TestFocusPage> createState() => _TestFocusPageState();
}

class _TestFocusPageState extends State<TestFocusPage> {
  final _webController = WebViewController();

  @override
  void initState() {
    super.initState();
    _load();
  }

  _load() async {
    await _webController.loadHtmlString(
      '<html><title>Test</title><body>Test! Tap here!</body></html>',
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: [
            Expanded(child: WebViewWidget(controller: _webController)),
            TextField(autofocus: true),
          ],
        ),
      ),
    );
  }
}
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

https://github.com/user-attachments/assets/3511a2a8-13ea-4203-8ce9-341240ac20a2

(Pictured is Microsoft Swift keyboard, but I have the same trouble with the default GBoard.)
</details>


### Logs

<details open><summary>Logs</summary>

```console
I/PlatformViewsController(12980): Hosting view in view hierarchy for platform view: 0
I/PlatformViewsController(12980): PlatformView is using SurfaceProducer backend
D/CompatibilityChangeReporter(12980): Compat change id reported: 236825255; UID 10590; state: ENABLED
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
D/CompatibilityChangeReporter(12980): Compat change id reported: 193247900; UID 10590; state: ENABLED
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
I/ImeTracker(12980): info.zverev.ilya.sonamobi:b75f095b: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(12980): showSoftInput() view=io.flutter.embedding.android.FlutterView{b9fb62a VFED..... .F....ID 0,0-1080,2394 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
I/ImeTracker(12980): info.zverev.ilya.sonamobi:a694a94d: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(12980): showSoftInput() view=io.flutter.embedding.android.FlutterView{b9fb62a VFED..... .F....ID 0,0-1080,2394 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
I/AssistStructure(12980): Flattened final assist data: 396 bytes, containing 1 windows, 3 views
D/InputConnectionAdaptor(12980): The input method toggled cursor monitoring on
D/InsetsController(12980): show(ime(), fromIme=true)
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
D/InsetsController(12980): show(ime(), fromIme=true)
I/ImeTracker(12980): info.zverev.ilya.sonamobi:a694a94d: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
I/cr_A11yState(12980): Enabled accessibility services list updated. [com.x8bit.bitwarden/.Accessibility.AccessibilityService]
I/cr_A11yState(12980): Informing listeners of changes.
I/cr_A11yState(12980): New AccessibilityState: State{isScreenReaderEnabled=false, isTouchExplorationEnabled=false, isPerformGesturesEnabled=false, isAnyAccessibilityServiceEnabled=true, isAccessibilityToolPresent=false, isSpokenFeedbackServicePresent=false, isTextShowPasswordEnabled=true, isOnlyPasswordManagersEnabled=true}
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
I/ImeTracker(12980): info.zverev.ilya.sonamobi:b75f095b: onShown
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
D/ProfileInstaller(12980): Installing profile for info.zverev.ilya.sonamobi
I/ImeTracker(12980): info.zverev.ilya.sonamobi:48448dd0: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(12980): showSoftInput() view=io.flutter.embedding.android.FlutterView{b9fb62a VFED..... .F...... 0,0-1080,2394 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController(12980): show(ime(), fromIme=true)
I/ImeTracker(12980): info.zverev.ilya.sonamobi:48448dd0: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
I/ImeTracker(12980): info.zverev.ilya.sonamobi:d085e5fa: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(12980): showSoftInput() view=io.flutter.embedding.android.FlutterView{b9fb62a VFED..... .F...... 0,0-1080,2394 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController(12980): show(ime(), fromIme=true)
I/ImeTracker(12980): info.zverev.ilya.sonamobi:d085e5fa: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
I/ImeTracker(12980): info.zverev.ilya.sonamobi:7a9f8344: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(12980): showSoftInput() view=io.flutter.embedding.android.FlutterView{b9fb62a VFED..... .F...... 0,0-1080,2394 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController(12980): show(ime(), fromIme=true)
I/ImeTracker(12980): info.zverev.ilya.sonamobi:7a9f8344: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
I/ImeTracker(12980): info.zverev.ilya.sonamobi:50ae35ea: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(12980): showSoftInput() view=io.flutter.embedding.android.FlutterView{b9fb62a VFED..... .F...... 0,0-1080,2394 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController(12980): show(ime(), fromIme=true)
I/ImeTracker(12980): info.zverev.ilya.sonamobi:50ae35ea: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
I/ImeTracker(12980): info.zverev.ilya.sonamobi:bc84b75b: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(12980): showSoftInput() view=io.flutter.embedding.android.FlutterView{b9fb62a VFED..... .F...... 0,0-1080,2394 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController(12980): show(ime(), fromIme=true)
I/ImeTracker(12980): info.zverev.ilya.sonamobi:bc84b75b: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
I/ImeTracker(12980): info.zverev.ilya.sonamobi:ead5ad71: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(12980): showSoftInput() view=io.flutter.embedding.android.FlutterView{b9fb62a VFED..... .F...... 0,0-1080,2394 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController(12980): show(ime(), fromIme=true)
I/ImeTracker(12980): info.zverev.ilya.sonamobi:ead5ad71: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
D/CompatibilityChangeReporter(12980): Compat change id reported: 289878283; UID 10590; state: ENABLED
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
W/RemoteInputConnectionImpl(12980): requestCursorAnchorInfo on inactive InputConnection
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
W/WindowOnBackDispatcher(12980): sendCancelIfRunning: isInProgress=falsecallback=ImeCallback=ImeOnBackInvokedCallback@91662709 Callback=android.window.IOnBackInvokedCallback$Stub$Proxy@a45abe9
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
I/ImeTracker(12980): info.zverev.ilya.sonamobi:f4fd2256: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(12980): showSoftInput() view=io.flutter.embedding.android.FlutterView{b9fb62a VFED..... .F....ID 0,0-1080,2394 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
I/ImeTracker(12980): info.zverev.ilya.sonamobi:e8c57057: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(12980): showSoftInput() view=io.flutter.embedding.android.FlutterView{b9fb62a VFED..... .F....ID 0,0-1080,2394 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
D/InputConnectionAdaptor(12980): The input method toggled cursor monitoring on
D/InsetsController(12980): show(ime(), fromIme=true)
I/ImeTracker(12980): info.zverev.ilya.sonamobi:f4fd2256: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
D/InsetsController(12980): show(ime(), fromIme=true)
I/ImeTracker(12980): info.zverev.ilya.sonamobi:e8c57057: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
I/ImeTracker(12980): info.zverev.ilya.sonamobi:d02228aa: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(12980): showSoftInput() view=io.flutter.embedding.android.FlutterView{b9fb62a VFED..... .F...... 0,0-1080,2394 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController(12980): show(ime(), fromIme=true)
I/ImeTracker(12980): info.zverev.ilya.sonamobi:d02228aa: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
I/ImeTracker(12980): info.zverev.ilya.sonamobi:ddd5f93b: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(12980): showSoftInput() view=io.flutter.embedding.android.FlutterView{b9fb62a VFED..... .F...... 0,0-1080,2394 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController(12980): show(ime(), fromIme=true)
I/ImeTracker(12980): info.zverev.ilya.sonamobi:ddd5f93b: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
I/ImeTracker(12980): info.zverev.ilya.sonamobi:9f9a66c: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(12980): showSoftInput() view=io.flutter.embedding.android.FlutterView{b9fb62a VFED..... .F...... 0,0-1080,2394 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController(12980): show(ime(), fromIme=true)
I/ImeTracker(12980): info.zverev.ilya.sonamobi:9f9a66c: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
I/ImeTracker(12980): info.zverev.ilya.sonamobi:71080674: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(12980): showSoftInput() view=io.flutter.embedding.android.FlutterView{b9fb62a VFED..... .F...... 0,0-1080,2394 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController(12980): show(ime(), fromIme=true)
I/ImeTracker(12980): info.zverev.ilya.sonamobi:71080674: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
I/ImeTracker(12980): info.zverev.ilya.sonamobi:8a0e19ea: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(12980): showSoftInput() view=io.flutter.embedding.android.FlutterView{b9fb62a VFED..... .F...... 0,0-1080,2394 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController(12980): show(ime(), fromIme=true)
I/ImeTracker(12980): info.zverev.ilya.sonamobi:8a0e19ea: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
E/FrameEvents(12980): updateAcquireFence: Did not find frame.
W/RemoteInputConnectionImpl(12980): requestCursorAnchorInfo on inactive InputConnection
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.3, on Fedora Linux 40 (KDE Plasma) 6.10.10-200.fc40.x86_64, locale ru_RU.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✗] Linux toolchain - develop for Linux desktop
    ✗ clang++ is required for Linux development.
      It is likely available from your distribution (e.g.: apt install clang), or can be downloaded from https://releases.llvm.org/
    ✗ ninja is required for Linux development.
      It is likely available from your distribution (e.g.: apt install ninja-build), or can be downloaded from https://github.com/ninja-build/ninja/releases
    ✗ GTK 3.0 development libraries are required for Linux development.
      They are likely available from your distribution (e.g.: apt install libgtk-3-dev)
[✓] Android Studio (version 2024.1)
[✓] Connected device (2 available)
[✓] Network resources

! Doctor found issues in 2 categories.
```

</details>