Skip to content

[windows] with solution! cannot make transparentBackground #2735

@iiiSnow

Description

@iiiSnow

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

On Windows, setting

initialSettings: InAppWebViewSettings(
  transparentBackground: true,
)

does not take effect — the background remains white.

Expected Behavior

transparentbackground

Steps with code example to reproduce

Set

initialSettings: InAppWebViewSettings(
  transparentBackground: true,
)

Run on Windows

Observe that the background is not transparent

Stacktrace/Logs

no logs

Flutter version

v3.32.6

Operating System, Device-specific and/or Tool

windows

Plugin version

v6.1.4

Additional information

🔍 Issue Analysis

1️⃣ File
windows/flutter/ephemeral/.plugin_symlinks/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.cpp

Lines 208–213:

wil::com_ptr<ICoreWebView2Controller2> webViewController2; 
if (succeededOrLog(webViewController->QueryInterface(IID_PPV_ARGS(&webViewController2)))) {
  if (!settings->transparentBackground) {
    webViewController2->put_DefaultBackgroundColor({ 0, 255, 255, 255 });
  }
}

The logic for transparentBackground is inverted here.
It should apply a transparent background when transparentBackground == true, not the opposite.

2️⃣ Same file, lines 1441–1445:

wil::com_ptr<ICoreWebView2Controller2> webViewController2;
if (succeededOrLog(webViewController->QueryInterface(IID_PPV_ARGS(&webViewController2)))) {
  if (fl_map_contains_not_null(newSettingsMap, "transparentBackground") && settings->transparentBackground != newSettings->transparentBackground) {
    BYTE alpha = newSettings->transparentBackground ? 0 : 255;
    webViewController2->put_DefaultBackgroundColor({ alpha, 255, 255, 255 });
  }
}

Here, newSettings->transparentBackground is always false,
so alpha never becomes 0.
When I forced alpha = 0, the transparent background worked correctly.

Notes

I’m not very familiar with C++, so I didn’t open a PR.
Just wanted to report this so you can double-check and fix it. 🙏

Linked: commitid: f3bf4b8
f3bf4b8

Self grab

  • I'm ready to work on this issue!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions