In this tutorial, you will learn how to add a WebView to your Flutter application.
What Is WebView?
WebView is a Flutter Widget that allows your mobile application to display web content. This component is pre-installed on your device and should be kept up to date to ensure you have the latest security updates and other bug fixes.
Adding WebView Flutter Plugin
Before you can start using WebView widget in your Flutter app, you will need to add one more plugin to a pubspec.yaml file. There’s an official plugin for Webview in Flutter which is available here and it is made by the Flutter team. Add it to your pubspec.yaml file where all the dependencies are listed.
Now that you have added the plugin to your dependencies, we will continue with the next step.
Below is a basic code that you need to create a WebView object.
In the code snippet above the WebView widget takes two parameters and they are:
- initialUrl – is the URL of the web resource you that it needs to load,
Note: If you want to make sure that the WebView should be responsive and cover the entire screen then you should add an Expanded widget to its parent.
Complete Code Example
Below is a complete code example of how to add a WebView widget to your Flutter mobile application.
I hope this tutorial was helpful to you. If you are interested in Flutter and are looking for other short tutorials like this, check the Flutter tutorials page on this website. If you prefer to learn by watching video tutorials, then have a look at the Futter video tutorials page.
Happy learning and mobile app development with Flutter to you!