Flutter Package : Membuat Webview Pada Flutter

Dalam tutorial kali ini kita akan mempelajari cara sederhana menggunakan webview pada flutter. Untuk menampilkan halaman web dalam aplikasi flutter kita membutuhkan package WebView.

Create New Flutter Project

# New Flutter project
$ flutter create my_webview_project

# Open this up inside of VS Code
$ cd my_webview_project && code .

Menambahkan Webview Plugin

Selanjutnya menambahkan plugin webview_flutter di dalam pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter
  webview_flutter: ^0.3.24

Source Code

lalu ubah code lib/main.dart seperti dibawah ini :

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

void main() {
  runApp(new MaterialApp(
    home: MyApp(
      title: 'belajarflutter view',
    ),
    debugShowCheckedModeBanner: false,
  ));
}

class MyApp extends StatelessWidget {
  final String title;
  MyApp({Key key, this.title}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: new WebView(
        initialUrl: "https://belajarflutter.com/",
        javascriptMode: JavascriptMode.unrestricted,
      ),
    );
  }
}

Output :

Membuat Webview Pada Flutter
output webview

Sumber

https://pub.dev/packages/webview_flutter

Default image
Herry Prasetyo
Today a reader Tomorrow a Leader

Leave a Reply