Skip to content

Quick Start: Your First Inline WebView

This page takes you from an empty Flutter app to a working inline WebView in under ten minutes. An inline WebView is a native browser surface embedded directly inside your Flutter widget tree — it participates in your layout, obeys your Scaffold, and shares the screen with your own Flutter widgets. That is the distinguishing property: the WebView is a child widget, not a separate window pushed onto the navigation stack.

By the end of this page you will have a scrollable web page rendered inside a Column, a controller in hand for programmatic navigation, a settings object controlling browser behaviour, and a progress bar tracking page load. Everything shown here is drawn from the shipped example application, so what you build will match what the maintainers actually run.

Sources: README.md, in_app_webview.dart

The whole quick start reduces to a single widget constructor with two required ideas: a creation parameter describing what to load, and a callback that hands you the controller once the native side is ready. The controller is your only handle on the page after that point — navigation, JavaScript evaluation, screenshots, and settings all flow through it.

flowchart TD
A["flutter pub add zikzak_inappwebview"] --> B["import the barrel file"]
B --> C["Construct InAppWebView<br/>with initialUrlRequest"]
C --> D["Native platform view created<br/>(Android / iOS / macOS / Windows / Linux / Web)"]
D --> E["onWebViewCreated fires<br/>delivering InAppWebViewController"]
E --> F["Use controller: loadUrl,<br/>evaluateJavascript, goBack, ..."]
C --> G["onLoadStart → onProgressChanged<br/>→ onLoadStop"]
G --> H["Page interactive"]
F --> H

The diagram above is the entire lifecycle you need to internalise. Note the ordering constraint that trips up most first-time users: initialUrlRequest is consumed at construction time, so it must be passed to the constructor rather than set afterwards, and the controller does not exist until onWebViewCreated fires. Any code that touches the controller before that callback runs is touching null.

Sources: in_app_webview.dart, in_app_webiew_example.screen.dart

Add the umbrella package to your application’s pubspec.yaml. The umbrella package is the only one you depend on directly; it federates out to per-platform packages automatically through the plugin declaration, so you never list Android, iOS, or any other platform package by hand.

dependencies:
zikzak_inappwebview: ^6.7.0

Then run flutter pub get. The umbrella package declares Dart SDK >=3.13.0 and Flutter >=3.50.0 as its floor, and registers all six endorsed platform packages as default_package entries — zikzak_inappwebview_android, _ios, _macos, _web, _windows, and _linux. Flutter’s plugin resolution picks the correct one for the platform you are building for.

Sources: pubspec.yaml, pubspec.yaml, pubspec.yaml

There is exactly one import to remember. The barrel file re-exports the platform interface types (WebUri, URLRequest, InAppWebViewSettings, and the rest) while hiding internal machinery such as ChannelController, IdGenerator, and Util, then layers the concrete widget and controller implementations on top.

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

Because the platform interface is re-exported, WebUri and URLRequest are available from this single import — you do not need to add zikzak_inappwebview_platform_interface to your dependencies for basic usage. The example application does list it explicitly only because it also imports the Web platform package directly.

Sources: zikzak_inappwebview.dart, main.dart, example/pubspec.yaml

Here is the complete minimal WebView. This is the smallest program that renders a real web page inside your app:

class MyWebScreen extends StatefulWidget {
const MyWebScreen({super.key});
@override
State<MyWebScreen> createState() => _MyWebScreenState();
}
class _MyWebScreenState extends State<MyWebScreen> {
InAppWebViewController? _controller;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('My First WebView')),
body: InAppWebView(
initialUrlRequest: URLRequest(url: WebUri('https://flutter.dev')),
onWebViewCreated: (controller) {
_controller = controller;
},
),
);
}
}

Three type constructors do all the work here. WebUri wraps a raw string and parses it defensively, exposing isValidUri so you can detect malformed input rather than crashing on the native side. URLRequest is the richer request envelope — it carries url, method, headers, body, cache policy, and timeout, but for a plain GET you only need url. InAppWebView itself is a StatefulWidget whose build method delegates entirely to the platform implementation, which is why the same Dart code renders through Android WebView, WKWebView, WebView2, WPE WebKit, or an iframe without branching.

Sources: web_uri.dart, url_request.zorphy.dart, in_app_webview.dart, README.md

The InAppWebView factory exposes a very large surface — well over fifty named callbacks — but only a handful matter on day one. The table below separates the ones you will actually type in your first hour from the ones you can safely ignore until later.

Parameter Required Purpose
initialUrlRequest No First navigation. A URLRequest wrapping a WebUri.
initialData No Load an inline HTML string instead of a URL.
initialFile No Load a bundled asset file path.
initialSettings No An InAppWebViewSettings object controlling browser behaviour.
onWebViewCreated No Fires once with the InAppWebViewController. Save this.
onLoadStart / onLoadStop No Navigation lifecycle, each receiving the controller and current WebUri?.
onProgressChanged No Integer 0–100 load progress, for progress bars.
onReceivedError No Network-level failure with a WebResourceError.
onReceivedHttpError No HTTP status failures with a WebResourceResponse.
shouldOverrideUrlLoading No Gate navigation; return NavigationActionPolicy.ALLOW or .CANCEL.
key No A GlobalKey — change it to force a full WebView rebuild.

The three initial-load parameters are mutually exclusive in practice: pick initialUrlRequest for remote pages, initialData for generated HTML, or initialFile for bundled assets. The example screen demonstrates all three, with the URL variant active and the other two commented out directly beneath it.

Sources: in_app_webview.dart, in_app_webiew_example.screen.dart

Step 4 — Keep the Controller and Drive the Page

Section titled “Step 4 — Keep the Controller and Drive the Page”

The controller is where the API becomes useful. InAppWebViewController implements Disposable and exposes the full navigation and JavaScript surface, with the most common operations also grouped into four lazily-created domain facades — navigation, javaScript, cookies, and settings. The top-level methods delegate to those facades, so controller.loadUrl(...) and controller.navigation.loadUrl(...) are equivalent; use whichever reads better at the call site.

// Navigate
await _controller?.loadUrl(urlRequest: URLRequest(url: WebUri('https://dart.dev')));
// Load generated HTML
await _controller?.loadData(
data: '<h1>Hello from Dart</h1>',
mimeType: 'text/html',
encoding: 'utf8',
baseUrl: WebUri('about:blank'),
);
// History
await _controller?.goBack();
await _controller?.goForward();
await _controller?.reload();
if (await _controller?.canGoBack() ?? false) { /* ... */ }
// Run JavaScript and read the result
final title = await _controller?.evaluateJavascript(source: 'document.title');

Two things are worth noting for beginners. First, every controller method is asynchronous and returns a Future — the call crosses a platform channel to native code, so await it or handle the error. Second, evaluateJavascript returns dynamic; the value is whatever the JavaScript expression produced, marshalled across the channel, so cast defensively.

Sources: in_app_webview_controller.dart, in_app_webview_controller.dart, in_app_webiew_example.screen.dart

Talking the Other Direction: JavaScript Handlers

Section titled “Talking the Other Direction: JavaScript Handlers”

JavaScript can call back into Dart. Register a named handler on the controller, then invoke it from the page through the injected bridge global. The global in this fork is window.zikzak_inappwebview, not window.flutter_inappwebview — this is the single most common migration surprise.

_controller?.addJavaScriptHandler(
handlerName: 'fromPage',
callback: (args) {
debugPrint('Page said: $args');
},
);
window.zikzak_inappwebview.callHandler('fromPage', { hello: 'world' });

Handlers are stored in a map keyed by name, and removeJavaScriptHandler / hasJavaScriptHandler let you audit what is registered. The full bridge contract — injection timing, the flutterInAppWebViewPlatformReady event, and handler lifecycle — is covered in The JavaScript Bridge Global and Handler Wiring.

Sources: in_app_webview_controller.dart, README.md

Step 5 — Configure Behaviour with Settings

Section titled “Step 5 — Configure Behaviour with Settings”

InAppWebViewSettings is a large generated entity: every field is nullable, every field has a copyWith counterpart, and unset fields mean “use the platform default”. This is deliberate — you specify only what you care about and inherit sane defaults for the rest. The example screen’s initial settings are a good starting template:

final settings = InAppWebViewSettings(
javaScriptEnabled: true,
domStorageEnabled: true,
databaseEnabled: true,
isFindInteractionEnabled: true,
isElementFullscreenEnabled: true,
upgradeKnownHostsToHTTPS: true,
);
InAppWebView(
initialSettings: settings,
initialUrlRequest: URLRequest(url: WebUri('https://flutter.dev')),
onWebViewCreated: (controller) { /* ... */ },
)

Settings are not immutable after construction. Pass the object to initialSettings for the first load, then mutate a copy and push it at runtime with controller.setSettings(settings: ...), reading the current state back with controller.getSettings(). The example’s settings dialog does exactly this: each switch calls currentSettings.copyWith(...) and immediately awaits setSettings.

A subset of settings are restart-only because they are baked into the native view at creation. upgradeKnownHostsToHTTPS is one of them — the example marks it “Requires Restart” in the UI and forces a rebuild by swapping the widget’s GlobalKey. Treat any setting labelled restart-only as a construction-time decision.

Sources: in_app_webview_settings.zorphy.dart, in_app_webiew_example.screen.dart, in_app_webiew_example.screen.dart, in_app_webview_controller.dart

The canonical WebView shell overlays a LinearProgressIndicator on top of the WebView inside a Stack, driven by onProgressChanged, and swaps in an empty Container once progress reaches 1.0. The URL bar and the progress bar both update from the same callback in the example, which keeps the displayed address in sync with what is actually loading.

body: SafeArea(
child: Column(
children: [
TextField(
controller: urlController,
onSubmitted: (value) {
var url = WebUri(value);
if (url.scheme.isEmpty) {
url = WebUri('https://www.google.com/search?q=$value');
}
_controller?.loadUrl(urlRequest: URLRequest(url: url));
},
),
Expanded(
child: Stack(
children: [
InAppWebView(
initialUrlRequest: URLRequest(url: WebUri('https://flutter.dev')),
onWebViewCreated: (c) => _controller = c,
onProgressChanged: (c, progress) {
setState(() => this.progress = progress / 100);
},
onLoadStop: (c, url) {
setState(() => this.url = url.toString());
},
),
progress < 1.0
? LinearProgressIndicator(value: progress)
: const SizedBox.shrink(),
],
),
),
],
),
),

Notice the url.scheme.isEmpty guard in onSubmitted. Users type bare search terms far more often than full URLs, and WebUri will happily parse flutter webview into a scheme-less URI that no WebView can load. Normalising to a search URL when the scheme is missing is the pattern the example uses, and it is worth copying verbatim.

Sources: in_app_webiew_example.screen.dart, in_app_webiew_example.screen.dart

Most platforms need nothing beyond flutter pub get. Three exceptions are worth knowing before you hit a confusing blank screen.

Platform Extra setup required
Android android:hardwareAccelerated="true" on the activity (present by default in the Flutter template). API 24+ / Android 7.0+.
iOS / macOS Nothing for basic usage. Deployment target iOS 15.0+ / macOS 12.0+. Camera and microphone need NSCameraUsageDescription / NSMicrophoneUsageDescription plus entitlements.
Windows WebView2 Runtime must be installed. Create a WebViewEnvironment in main() before runApp.
Linux WPE WebKit 2.50+ and the wpe-webkit-2.0, wpe-platform-2.0, wpe-platform-headless-2.0, wpe-1.0 development packages.
Web Nothing.

The Windows path is the one that most often surprises people, because the environment object must exist before the widget is constructed and is then passed into every InAppWebView via webViewEnvironment. The example’s main() shows the full pattern, including the availability assertion that fails fast when no runtime is present.

Sources: README.md, AndroidManifest.xml, Info.plist, main.dart

Symptom Likely cause Fix
Blank white WebView, no error Controller used before onWebViewCreated, or initialUrlRequest never supplied Move all controller access inside the callback; verify the URL has a scheme.
WebUri reports isValidUri == false Malformed string passed to WebUri Normalise user input; default the scheme to https://.
JavaScript handler never fires Wrong bridge global name Call window.zikzak_inappwebview.callHandler(...), not flutter_inappwebview.
Setting change has no effect Setting is restart-only Rebuild the widget with a new GlobalKey.
Nothing renders on Windows WebView2 Runtime missing Install the runtime; assert WebViewEnvironment.getAvailableVersion() in main().
setSettings throws after dispose Controller used past widget disposal Hold the controller in State and null it in dispose.

Sources: README.md, in_app_webiew_example.screen.dart, main.dart, in_app_webview.dart

By default, popping a route disposes the WebView and destroys its page state — scroll position, form contents, session storage. When you need to preserve it across navigation, construct an InAppWebViewKeepAlive once, hold it in a parent that outlives the route, and pass it as keepAlive. The object is nothing more than a generated string identity; the native side uses that identity to retain the underlying view rather than destroying it.

final keepAlive = InAppWebViewKeepAlive();
InAppWebView(
keepAlive: keepAlive,
initialUrlRequest: URLRequest(url: WebUri('https://flutter.dev')),
onWebViewCreated: (controller) { /* ... */ },
)

The disposal contract, the keep-alive identity model, and the interaction with headless instances are examined in depth in Disposal Lifecycle and KeepAlive Patterns.

Sources: in_app_webview_keep_alive.dart, in_app_webview.dart

You now have a functioning inline WebView. The natural progression from here follows the catalog’s Get Started arc, then fans out into the deep dives:

  1. Installation and Platform Requirements — the full per-platform matrix, including Linux WPE packages, Windows WebView2 provisioning, and the OpenHarmony add-on.
  2. The JavaScript Bridge Global and Handler Wiring — the complete window.zikzak_inappwebview contract, injection timing, and handler lifecycle.
  3. Example App and Screen-by-Screen Walkthrough — a guided tour of every screen in the shipped example, including the edge-to-edge, headless, and passkey demos.
  4. InAppWebView Widget and InAppWebViewController — the exhaustive constructor and controller reference.
  5. Domain Controller Facades: Navigation, JavaScript, Cookies, Settings — how the controller surface is partitioned and when to use each facade.

If you are arriving from flutter_inappwebview, read Migrating from flutter_inappwebview next — the import swap is one line, but the bridge global rename and the version-line mapping will save you an afternoon.