flutter - 如何在颤动的 webview 中禁用暗模式?
问题描述
我在这里有一个简单的代码,它只是应该使用 webview_flutter 显示一个网页(https://pub.dev/packages/webview_flutter)
但是,它会自动启用暗模式并显示网站的暗版本。我怎样才能防止这种情况?
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
MyAppState createState() => MyAppState();
}
class MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Mobile App"),
backgroundColor: Colors.blueGrey,
),
body: WebView(
initialUrl: 'https://flutter.dev',
javascriptMode: JavascriptMode.unrestricted,
)),
debugShowCheckedModeBanner: false,
);
}
}
解决方案
设置您的 MaterialApp 主题。
MaterialApp(
theme: ThemeData.light(), //<- specify here light()
home: Scaffold(
appBar: AppBar(
title: Text("Mobile App"),
backgroundColor: Colors.blueGrey,
),
body: WebView(
initialUrl: 'https://flutter.dev',
javascriptMode: JavascriptMode.unrestricted,
)),
debugShowCheckedModeBanner: false,
);
推荐阅读
- php - 使用动态变量访问 PHP 数组中的特定值
- javascript - 当我尝试在 android 上运行 react native 应用程序时出现错误
- python - 不期望使用正则表达式输出打印列表
- python-3.x - 如何在 Tensorflow 2.0 中计算输出 wrt 输入的梯度
- android-studio - 我们如何将 Android Studio 与 Github 连接起来?
- matplotlib - 如何为带有子图的图形添加任意大的白边距?
- sql - 我正在尝试在两个表之间进行交叉连接并消除重复
- node.js - NodeJS图像未上传且类别名称显示变量而不是值
- r - 如何对另一个子集进行子集化或“分组”?
- html - 如何防止此 HTML 文本换行?