How to Use Webviews in Flutter
1. First, create a new flutter project with a free name. We are using null safety version of flutter, and minsdkVersion 19.
2. Open the pubspec.yaml file. Then add the webview_flutter: ^ 3.0.0 like the example below to download the flutter webview package. After adding CTRL + S to download the package.
3. Then open the main.dart file then change it with the script below. https://porkaone.com is an example of the website that we will display. You can change it with another website address
// ignore_for_file: unused_import, import_of_legacy_library_into_null_safe, prefer_const_constructors, unnecessary_new
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() => runApp(App());
class App extends StatelessWidget {
const App({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text("Flutter Webview"),
),
body: new WebView(
initialUrl: "https://porkaone.com",
javascriptMode: JavascriptMode.unrestricted,
)),
);
}
}
Hasil Akhir |
You can improvise by adding swiperefresh, loading indicators, listing websites using listview, and so on.
That's all for this short tutorial, about how to display a website in flutter with webview. Hopefully useful and can be applied. If you have questions, please ask directly in the comments column below. That is all and thank you.
0 Comments
Come on ask us and let's discuss together
Emoji