skip to Main Content

I installed webview_flutter. I ran pub get too. also, I added Import ‘package:webview_flutter/webview_flutter.dart’. But actually I can’t use WebView widget In flutter. This is my code. WebView occured not found error.

import 'dart:io'; // Add this import.
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class WebViewExample extends StatefulWidget {
  @override
  _WebViewExampleState createState() => _WebViewExampleState();
}

class _WebViewExampleState extends State<WebViewExample> {
  @override
  void initState() {}
 
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
      title: const Text('WebView Example'),
    ),
    body: Builder(builder: (BuildContext context){
      return WebView(
        initialUrl: 'https://flutter.dev',
      );
    }),
    );
  }
}

2

Answers


  1. You need a WebViewWidget and a WebViewController

     @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(title: const Text('Flutter Simple Example')),
        body: WebViewWidget(controller: controller),
      );
    }
    

    See enter link description here

    Login or Signup to reply.
  2. 1- The Webview supports SDK 19+ on Android and 9.0+ on IOS so check in the SDK Manager for your SDK version and update it… and check your minSdkVersion in your android build gradle

    Or it could be a network issue so…

    2- Test it on an actual device if it works then you need to do the following modifications if you’re using a virtual device

    Press Windows -> Search for View Network Connections -> Right Click on your network -> Properties -> Click on TCP IPv4 -> Properties -> Check Use the following DNS Server -> Change to 8.8.8.8 the first one and 0.0.0.0 the second one

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search