[webview_flutter_android] Adds support to opt out of Android inset changes (#11192)

For WebView versions >=144, support has been added for [displayCutout()](https://developer.android.com/reference/androidx/core/view/WindowInsetsCompat.Type#displayCutout%28%29) insets and [systemBars()](https://developer.android.com/reference/androidx/core/view/WindowInsetsCompat.Type#systemBars%28%29) insets. This is causing WebViews to incorrectly report that it is obscured by a system bar or display cutout as demonstrated in this [issue](https://github.com/flutter/flutter/issues/182208). 

This adds the opt out for inset changes as explained [in this chromium doc](https://chromium.googlesource.com/chromium/src/+/HEAD/android_webview/docs/insets.md#opt_out). It seems Flutter handles safe areas for platform views, so the `AndroidWebViewController` can zero out inset changes to the WebContent.

iOS does [something similar](https://github.com/flutter/packages/blob/main/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebViewProxyAPIDelegate.swift#L50). And it also sets [UIScrollView.contentInsetAdjustmentBehavior](https://developer.apple.com/documentation/uikit/uiscrollview/contentinsetadjustmentbehavior-swift.property) to `Never`. My assumption was that this was never done for Android, because `WebView`s didn't receive these inset changes until this version.

<details open><summary>Code sample</summary>

main.dart in `webview_flutter_android`:

```dart
import 'package:flutter/material.dart';
import 'package:webview_flutter_android/webview_flutter_android.dart';
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';

const String htmlPage = '''
<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WebView Test</title>
    <style>
        header {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            padding-top: env(safe-area-inset-top);
            background-color: blue;
            color: #ffffff;
        }
        .content {
            padding-top: 72px;
        }
    </style>
</head>
<body>
<div class="container">
    <header><h1>Webview AppBar</h1></header>
    <div class="content">
        <p>This is some webview content</p>
    </div>
</div>
</body>
</html>
''';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late final PlatformWebViewController _controller;

  @override
  void initState() {
    super.initState();

    _controller =
        PlatformWebViewController(
            const PlatformWebViewControllerCreationParams(),
          )
          ..setJavaScriptMode(JavaScriptMode.unrestricted)
          ..loadHtmlString(htmlPage);
    // Uncomment to fix.
    /*
   (_controller as AndroidWebViewController).setInsetsForWebContentToIgnore(
      <AndroidWebViewInsets>[
        AndroidWebViewInsets.displayCutout,
        AndroidWebViewInsets.systemBars,
      ],
    );
    */
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.primary,
        toolbarHeight: 0,
      ),
      body: PlatformWebViewWidget(
        PlatformWebViewWidgetCreationParams(controller: _controller),
      ).build(context),
    );
  }
}
```

</details>

<details open><summary>Screenshots</summary>

| Before      | After |
| ----------- | ----------- |
| <img width="1080" height="2424" alt="Screenshot_20260313_151847" src="https://github.com/user-attachments/assets/202da750-dc9e-4bfd-8a84-72462e405781" /> | <img width="1080" height="2424" alt="Screenshot_20260313_151957" src="https://github.com/user-attachments/assets/900554b9-2e85-4e28-83e9-71f795974191" />       |

</details>

Fixes https://github.com/flutter/flutter/issues/182208

## Pre-Review Checklist

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
11 files changed
tree: 8c743fcb68c2ff578223ad2e964010ce0a6ca2ca
  1. .agents/
  2. .ci/
  3. .claude/
  4. .gemini/
  5. .github/
  6. agent-artifacts/
  7. packages/
  8. script/
  9. third_party/
  10. .ci.yaml
  11. .clang-format
  12. .direnv
  13. .gitattributes
  14. .gitignore
  15. .metadata
  16. AGENTS.md
  17. analysis_options.yaml
  18. AUTHORS
  19. CONTRIBUTING.md
  20. customer_testing.bat
  21. customer_testing.sh
  22. LICENSE
  23. README.md
  24. SUGGESTED_REVIEWERS.md
README.md

Flutter Packages

Release Status Flutter CI Status

This repo is a companion repo to the main flutter repo. It contains the source code for Flutter's first-party packages (i.e., packages developed by the core Flutter team). Check the packages directory to see all packages.

These packages are also available on pub.

Issues

Please file any issues, bugs, or feature requests in the main flutter repo. Issues pertaining to this repository are labeled “package”.

Contributing

If you wish to contribute a new package to the Flutter ecosystem, please see the documentation for developing packages. You can store your package source code in any GitHub repository (the present repo is only intended for packages developed by the core Flutter team). Once your package is ready you can publish to the pub repository.

If you wish to contribute a change to any of the existing packages in this repo, please review our contribution guide, and send a pull request.

Packages

These are the packages hosted in this repository:

PackagePubPointsUsageIssuesPull requests
animationspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
camerapub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
cross_filepub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
cupertino_iconspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
cupertino_uipub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
espressopub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
extension_google_sign_in_as_googleapis_authpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
file_selectorpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
flutter_lintspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
flutter_plugin_android_lifecyclepub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
flutter_svgpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
flutter_svg_testpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
flutter_template_imagespub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
go_routerpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
go_router_builderpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
google_adsensepub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
google_fontspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
google_maps_flutterpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
google_sign_inpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
image_pickerpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
interactive_media_adspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
in_app_purchasepub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
local_authpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
material_uipub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
metrics_centerpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
multicast_dnspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
path_parsingpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
path_providerpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
pigeonpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
pointer_interceptorpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
plugin_platform_interfacepub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
quick_actionspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
google_identity_services_webpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
mustache_templatepub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
rfwpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
shared_preferencespub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
standard_message_codecpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
two_dimensional_scrollablespub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
url_launcherpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
vector_graphicspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
vector_graphics_codecpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
vector_graphics_compilerpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
video_playerpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
web_benchmarkspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
webview_flutterpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
xdg_directoriespub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label