fluttercommunity / flutter_webview_plugin

Community WebView Plugin - Allows Flutter to communicate with a native WebView.
https://pub.dev/packages/flutter_webview_plugin
Other
1.48k stars 929 forks source link

Disable dark mode in web view #909

Closed tony123S closed 3 years ago

tony123S commented 3 years ago

I am developing an application in Flutter (with a webview) and when dark mode is activated on the device, the webview changes the colors of the web (text and background) to make it dark, creating a horrible result.

epynic commented 3 years ago

This is not related to the plugin, you can override the current theme by wrapping the desired widget in a Theme widget something similar to :

@override
      Widget build(BuildContext context) {
        return new Theme(
          child: appBar,
          data: new ThemeData.dark()
        );
      }
tony123S commented 3 years ago

why is ThemeData.dark()?

epynic commented 3 years ago

You can use the themedata as you want, ThemeData.light()

https://api.flutter.dev/flutter/material/ThemeData-class.html https://api.flutter.dev/flutter/material/Theme/Theme.html

tony123S commented 3 years ago

the content color still change

tony123S commented 3 years ago

I managed to fix it by adding this line in android/app/src/res/values/styles.xml <item name="android:forceDarkAllowed">false</item>

Here my full code


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             Flutter draws its first frame -->
        <item name="android:forceDarkAllowed">false</item>
        <item name="android:windowBackground">@drawable/launch_background</item>
    </style>
</resources>