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 createState() => _HomePageState(); } class _HomePageState extends State { 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: [ WebViewWidget( controller: controller, ), _loading() ], ); } _loading() { return _isLoading == true ? Container( decoration: const BoxDecoration(color: Colors.white), child: const Center( child: CircularProgressIndicator(), ), ) : const Text(''); } }