How to create webview in flutter

Viewed 1866

I am trying to use web views in flutter. I have followed this medium article which depicts how we can create a simple application using Flutter embed webview.

https://medium.com/@ekosuprastyo15/webview-in-flutter-example-a11a24eb617f

I am able to create app successfully but right now that app is opening on button click as shown in the above article.

What I want - Now I want to create an application that loads a URL in webview on load (i.e. user won't have to click on any button or link to open that URL).

What we have tried so far?

We have tried flutter url_launcher plugin and flutter_webview_plugin plugin.

2 Answers

Add this lib Flutter WebView

import 'package:webview_flutter/webview_flutter.dart';

return Scaffold(
      appBar: AppBar(
        title: const Text('Flutter WebView example'),
      ),
      body: const WebView(
        initialUrl: 'https://flutter.io',
        javascriptMode: JavascriptMode.unrestricted,
      ),
    );

if you want to directly open website that you want without pressing any button you should give initial Url. but you should nagivate.push from other pages to here. it is like that;

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
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("webview"),
      ),
      body: WebView(
        initialUrl: "https://www.google.com/",
        javascriptMode: JavascriptMode.unrestricted,
      ),
    );
  }
}
Related