home_page.dart 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import 'package:flutter/material.dart';
  2. import 'package:webview_flutter/webview_flutter.dart';
  3. /// Description:
  4. /// Time : 2021年12月03日 Friday
  5. /// Author : liuyuqi.gov@msncn
  6. class HomePage extends StatefulWidget {
  7. String url;
  8. HomePage({Key? key, required this.url}) : super(key: key);
  9. @override
  10. State<HomePage> createState() => _HomePageState();
  11. }
  12. class _HomePageState extends State<HomePage> {
  13. bool _isLoading = true;
  14. @override
  15. Widget build(BuildContext context) {
  16. var controller = WebViewController()
  17. ..setJavaScriptMode(JavaScriptMode.unrestricted)
  18. ..setBackgroundColor(const Color(0x00000000))
  19. ..setNavigationDelegate(
  20. NavigationDelegate(
  21. onProgress: (int progress) {
  22. // Update loading bar.
  23. },
  24. onPageStarted: (String url) {},
  25. onPageFinished: (String url) {},
  26. onWebResourceError: (WebResourceError error) {},
  27. onNavigationRequest: (NavigationRequest request) {
  28. if (request.url.startsWith('https://www.youtube.com/')) {
  29. return NavigationDecision.prevent;
  30. }
  31. return NavigationDecision.navigate;
  32. },
  33. ),
  34. )
  35. ..loadRequest(Uri.parse(widget.url));
  36. return Stack(
  37. children: <Widget>[
  38. WebViewWidget(
  39. controller: controller,
  40. ),
  41. _loading()
  42. ],
  43. );
  44. }
  45. _loading() {
  46. return _isLoading == true
  47. ? Container(
  48. decoration: const BoxDecoration(color: Colors.white),
  49. child: const Center(
  50. child: CircularProgressIndicator(),
  51. ),
  52. )
  53. : const Text('');
  54. }
  55. }