web_view.dart 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import 'package:flutter/material.dart';
  2. import 'package:webview_flutter/webview_flutter.dart';
  3. class WebView extends StatelessWidget{
  4. late final WebViewController controller;
  5. WebView({super.key, required String url}){
  6. controller = WebViewController()
  7. ..setJavaScriptMode(JavaScriptMode.unrestricted)
  8. ..setBackgroundColor(const Color(0x00000000))
  9. ..setNavigationDelegate(
  10. NavigationDelegate(
  11. onProgress: (int progress) {
  12. // Update loading bar.
  13. },
  14. onPageStarted: (String url) {},
  15. onPageFinished: (String url) {},
  16. onWebResourceError: (WebResourceError error) {},
  17. // onNavigationRequest: (NavigationRequest request) {
  18. // if (request.url.startsWith('https://www.youtube.com/')) {
  19. // return NavigationDecision.prevent;
  20. // }
  21. // return NavigationDecision.navigate;
  22. // },
  23. ),
  24. )
  25. ..loadRequest(Uri.parse(url));
  26. }
  27. @override
  28. Widget build(BuildContext context) {
  29. return Scaffold(
  30. appBar: AppBar(title: const Text('')),
  31. body: WebViewWidget(controller: controller),
  32. );
  33. }
  34. }