-
Notifications
You must be signed in to change notification settings - Fork 74
/
webview_flutter.dart
45 lines (40 loc) · 1.37 KB
/
webview_flutter.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class MyWebviewFlutter extends StatefulWidget {
const MyWebviewFlutter({Key? key}) : super(key: key);
@override
State<MyWebviewFlutter> createState() => _MyWebviewFlutterState();
}
class _MyWebviewFlutterState extends State<MyWebviewFlutter> {
late WebViewController controller;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Webview Flutter')),
body: WebView(
javascriptMode: JavascriptMode.unrestricted,
initialUrl: 'https://amazon.com',
onWebViewCreated: (controller) {
this.controller = controller;
},
onPageStarted: (url) {
debugPrint('New website: $url');
},
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.import_export, size: 32),
onPressed: () async {
controller.runJavascript(
"document.getElementsByTagName('header')[0].style.display='none'",
);
controller.runJavascript(
"document.getElementsByTagName('footer')[0].style.display='none'",
);
// final url = await controller.currentUrl();
// print('Previous Website: $url');
// controller.loadUrl('https://youtube.com');
},
),
);
}
}