我正在使用webview_flutter插件,当 webview 在暗模式设备上的任何小米上打开时,它会强制暗模式,我不知道如何避免它
这是我的代码:
import 'dart:async';
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class CdsWebView extends StatefulWidget {
const CdsWebView({
Key key,
@required this.url,
}) : super(key: key);
final String url;
@override
_CdsWebViewState createState() => _CdsWebViewState();
}
class _CdsWebViewState extends State<CdsWebView> {
final Completer<WebViewController> _controller =
Completer<WebViewController>();
WebViewController _webViewController;
bool isLoading = true;
@override
void initState() {
super.initState();
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Builder(builder: (BuildContext context) {
return Stack(children: <Widget>[
WebView(
initialUrl: widget.url,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
_webViewController = webViewController;
},
onPageFinished: (finish) {
this.setState(() {
isLoading = false;
});
},
),
isLoading
? Container(
child: Center(
child: CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation<Color>(Colors.red),
),
),
)
: Container()
]);
}),
),
);
}
}
如果在颤动中无法防止,有没有办法在 webview 页面中防止?
它会像这样更改背景和文本颜色:
WebView 测试页代码:
<html>
<head>
</head>
<body style="
display: flex;
justify-content: center;
align-items: center;">
<h1 style="font-family: Arial;">
My WebView Page
</h1>
</body>
</html>