Search code examples
flutteruser-interface

How to get this WebView_Flutter to display HTML?


I was following this tutorial to code https://www.youtube.com/watch?v=wPf-7rrng-8 But i'm getting a screen error on emulator screen.

enter image description here

I want to display the html (youtube) using the WebView_Flutter package.

Here's to code:

import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class WebView extends StatefulWidget {
  const WebView({super.key});

  @override
  State<WebView> createState() => _WebViewState();
}

class _WebViewState extends State<WebView> {

  final controller = WebViewController()
  
  ..setJavaScriptMode(JavaScriptMode.disabled) 
  ..loadRequest(Uri.parse('https://www.youtube.com/'));

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: WebViewWidget(controller: controller),
    );
  }
}

I've updated the package to the latest version in pubspec.yaml.


Solution

  • I found the reason. The original code was already working, in real android phone, but i was trying it out on Chrome DevTool, and it won't work there for some reason.