12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import 'package:flutter/material.dart';
- import 'package:webview_flutter/webview_flutter.dart';
- /// Description:
- /// Time : 2021年12月03日 Friday
- /// Author : liuyuqi.gov@msncn
- class HomePage extends StatefulWidget {
- String url;
- HomePage({Key? key, required this.url}) : super(key: key);
- @override
- State<HomePage> createState() => _HomePageState();
- }
- class _HomePageState extends State<HomePage> {
- bool _isLoading = true;
- @override
- Widget build(BuildContext context) {
- var controller = WebViewController()
- ..setJavaScriptMode(JavaScriptMode.unrestricted)
- ..setBackgroundColor(const Color(0x00000000))
- ..setNavigationDelegate(
- NavigationDelegate(
- onProgress: (int progress) {
- // Update loading bar.
- },
- onPageStarted: (String url) {},
- onPageFinished: (String url) {},
- onWebResourceError: (WebResourceError error) {},
- onNavigationRequest: (NavigationRequest request) {
- if (request.url.startsWith('https://www.youtube.com/')) {
- return NavigationDecision.prevent;
- }
- return NavigationDecision.navigate;
- },
- ),
- )
- ..loadRequest(Uri.parse(widget.url));
- return Stack(
- children: <Widget>[
- WebViewWidget(
- controller: controller,
- ),
- _loading()
- ],
- );
- }
- _loading() {
- return _isLoading == true
- ? Container(
- decoration: const BoxDecoration(color: Colors.white),
- child: const Center(
- child: CircularProgressIndicator(),
- ),
- )
- : const Text('');
- }
- }
|