In this guide, we will learn how to implement the WebView in Flutter by using the external package name webview_flutter. WebView in flutter is a plugin that provides a WebView widget on Android and iOS. This plugin is used to display web pages on both Android and iOS devices. We will learn how to use the webview_flutter plugin to load webpages from its URL or a local source. webview_flutter exports a WebView class. This class starts and creates a new web view and renders the set webpage (via its URL) inside the WebView widget. The WebView can be controlled using a WebViewController that is passed to the onWebViewCreated callback once the WebView is created.
To render the WebView widget, we need to import the webview_flutter package:

Installation

Run this command:

With Flutter:

 $ flutter pub add webview_flutter

This will add a line like this to your package’s pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  webview_flutter: ^3.0.4

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:webview_flutter/webview_flutter.dart';

Next, we set the minimum SDK version needed for the webview_flutter plugin. Open android/app/build.gradle our project and add the below configuration code to the android → defaultConfig section:

android {
    defaultConfig {
        minSdkVersion 19
    }
}

Let’s take an example of how we can implement the WebView in our flutter application.

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

class WebViewScreen extends StatefulWidget {
  const WebViewScreen({Key? key}) : super(key: key);

  @override
  State<WebViewScreen> createState() => _WebViewScreenState();
}

class _WebViewScreenState extends State<WebViewScreen> {
  late WebViewController controller;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('WebView in Flutter'),
        centerTitle: true,
      ),
      body: WebView(
        javascriptMode: JavascriptMode.unrestricted,
        initialUrl: 'https://flutterguide.com/',
        onWebViewCreated: (controller) {
          controller = controller;
        },
      ),
    );
  }
}

Meanwhile, when we run this application in the emulator or device, we should get the UI similar to the screenshot below:

Get the full snippet from here