[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.
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.
Please file any issues, bugs, or feature requests in the main flutter repo. Issues pertaining to this repository are labeled “package”.
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.
These are the packages hosted in this repository: