skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. You can use loadHtmlString to load html to the webview.

      controller.loadHtmlString(yourHtml);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search