【发布时间】:2020-04-03 07:28:04
【问题描述】:
我是 Flutter 的新手,目前我正在制作一个非常简单的应用程序,它只是一个 WebView。我的问题是如何将这段代码插入到我的 Flutter WebView 中?
footer#footer, div#st_notification_1, #sidebar_box {
display: none!important;
}
目前,我正在尝试在我的一个应用程序选项卡上使用 Flutter 团队的 WebView 插件。我试图加载和隐藏页脚的网站是:
下面是我试图隐藏页脚的那个标签 Webview 的代码
更新:已修复。下面的代码对我有用
注意:我也重新检查了网站,把上面网站的footer类名对应的getElementsById改成了getElementsByClassName。
注意2:Flutter 包中有很多 WebView 应用,我使用的是 Flutter 团队的 Flutter Webview。
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
class ProfileAccount extends StatefulWidget {
ProfileAccount({Key key}) : super(key: key);
@override
_ProfileAccountState createState() => _ProfileAccountState();
}
class _ProfileAccountState extends State<ProfileAccount> {
WebViewController _myController;
final Completer<WebViewController> _controller =
Completer<WebViewController>();
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: WebView(
initialUrl: 'https://syncshop.online/en/login',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (controller) {
_myController = controller;
},
onPageFinished: (initialUrl) {
_myController.evaluateJavascript("document.getElementsByClassName('footer-container')[0].style.display='none';");
},
)
),
);
}
}
【问题讨论】:
标签: flutter flutter-layout flutter-dependencies