Skip to content

The Platform Interface: The Contract Seam

zikzak_inappwebview_platform_interface is the only package in the monorepo that every other package depends on and that depends on none of them. It contains no platform code at all — no Kotlin, no Swift, no C++, no HTML — only abstract Dart classes, immutable parameter objects, and the serialized entity model that crosses the method-channel boundary. That makes it the contract seam: the place where “what the app asks for” is separated from “how a given engine delivers it”, and the only surface a new platform implementation has to satisfy in order to be a drop-in backend for the plugin.

Sources: pubspec.yaml, README.md

The repository is a federated plugin: the app-facing package declares default_package entries for six platforms, and each of those packages registers itself behind a single abstract class at load time. The platform interface is the vocabulary all seven sides agree on. Read the diagram bottom-up: implementations at the bottom satisfy contracts in the middle, and the app-facing API at the top only ever speaks the middle language.

graph TD
App["Your Flutter app"] --> Core["zikzak_inappwebview<br/>InAppWebView · InAppWebViewController · facades"]
Core --> PI["zikzak_inappwebview_platform_interface<br/>InAppWebViewPlatform · Platform* contracts · entities"]
PI --> A["android"]
PI --> I["ios"]
PI --> M["macos"]
PI --> L["linux"]
PI --> W["windows"]
PI -->Wb["web"]
PI --> O["ohos"]
Module["zikzak_inappwebview_module<br/>pool · VCR · recipes · agent tools"] --> Core

Note two properties of this graph. The module tier sits beside the platform packages, not below them: it consumes only the core’s public API and is structurally forbidden from importing the interface directly. And the interface has exactly one direction of dependency — implementations point at it, it points at nothing in the repo.

Sources: pubspec.yaml, SPLIT_MAP.md, pubspec.yaml

The package is a thin barrel over a wide src tree. The public entry point is four lines; everything else is re-exported through a chain of main.dart files so consumers write one import and get the whole vocabulary.

Region Contents Role in the contract
src/inappwebview_platform.dart InAppWebViewPlatform The factory registry — one createPlatformX method per public type
src/in_app_webview/ Controller, widget, headless, PlatformWebViewCreationParams, four domain delegates The behavioral surface
src/domain/entities/ 98 entity/enum directories, 88 generated .zorphy.dart files The wire model
src/types/ 192 export lines of entity and enum re-exports Stable import path for the model
src/platform_*.dart Cookie manager, localhost server, tracing, service worker, auth DB Process-level singletons
src/util.dart, src/web_uri.dart ChannelController, Color_, IdGenerator, WebUri Shared plumbing primitives

Sources: zikzak_inappwebview_platform_interface.dart, main.dart, types/main.dart, in_app_webview/main.dart

The entity layer is generated, not hand-written. Each entity is declared as an abstract $-prefixed class annotated with @Zorphy, and build_runner emits a concrete immutable twin plus json_serializable glue into two part files. The build scope is deliberately narrow — generation runs only over lib/src/domain/entities/**, so no other file in the package can be silently rewritten by a codegen pass.

Sources: build.yaml, GENERATOR_NOTES.md, in_app_webview_settings.dart

The whole mechanism is a single guarded static setter. InAppWebViewPlatform extends PlatformInterface with a private token object; the setter refuses null and calls PlatformInterface.verify(instance, _token), so only a subclass constructed with the matching token can ever occupy the slot. Every platform package exposes the same registerWith entry point, which Flutter’s generated registrant calls during plugin attachment.

sequenceDiagram
participant App
participant Core as InAppWebViewController
participant Reg as InAppWebViewPlatform
participant Impl as AndroidInAppWebViewPlatform
participant Ctl as AndroidInAppWebViewController
App->>Core: InAppWebViewController.fromPlatformCreationParams
Core->>Reg: PlatformInAppWebViewController(params)
Reg->>Reg: assert instance != null
Reg->>Impl: createPlatformInAppWebViewController(params)
Impl->>Ctl: new(params)
Reg->>Reg: PlatformInterface.verify(result, _token)
Reg-->>Core: PlatformInAppWebViewController
Core-->>App: InAppWebViewController(platform:)

The failure mode is explicit rather than implicit: if no implementation registered, the factory asserts with a message naming InAppWebViewPlatform.instance and pointing test authors at their own fake implementation. That single sentence is what makes the interface package testable in isolation — a unit test substitutes a stub instance and never touches a native engine.

Sources: inappwebview_platform.dart, platform_inappwebview_controller.dart, inappwebview_platform.dart

Each backend overrides only the subset it supports; everything else inherits the base class’s UnimplementedError default. That asymmetry is intentional and is the mechanism by which a platform can ship partial support without breaking the contract.

Package Registration entry Notable overrides beyond the WebView trio
android AndroidInAppWebViewPlatform.registerWith() Cookie, auth DB, storage, proxy, tracing, service worker, process config, asset loader, features
ios IOSInAppWebViewPlatform.registerWith() Cookie, auth DB, storage, proxy, web message family, web authentication session
macos MacOSInAppWebViewPlatform.registerWith() Cookie, proxy, print, browser, plus setHeadlessMaxLiveWebViews
linux LinuxInAppWebViewPlatform.registerWith() Cookie, auth DB, storage, proxy, web message family
windows ZikzakInAppWebViewWindows.registerWith() Cookie and PlatformWebViewEnvironment (WebView2 profile plumbing)
web ZikzakInAppWebViewWeb.registerWith(registrar) Widget, find-interaction, headless only
ohos OhosInAppWebViewPlatform.registerWith() Widget, controller, static controller, cookie

Sources: inappwebview_platform.dart, inappwebview_platform.dart, inappwebview_platform.dart, zikzak_inappwebview_windows.dart, in_app_webview_web_platform.dart, platform.dart

The web package needs a Registrar because it is a flutter_web_plugins plugin, and it is registered through a pluginClass rather than a dartPluginClass. OHOS uses the dartPluginClass form. Both styles converge on the same setter, which is the point of routing registration through a data field in pubspec.yaml instead of a hard-coded call in the core.

Sources: zikzak_inappwebview_web.dart, pubspec.yaml, pubspec.yaml

Every abstract contract in the package repeats the same three-part shape: a public factory that routes through the registry, a @protected .implementation constructor that only platform authors may call, and a private static token used for verification. The table below shows the pattern applied consistently across unrelated subsystems, which is what allows the package to be extended without a security or type-safety hole.

Contract Factory verifies Implementation constructor
PlatformInAppWebViewController PlatformInterface.verify(..., _token) PlatformInAppWebViewController.implementation(params)
PlatformCookieManager PlatformInterface.verify(cookieManager, _token) PlatformCookieManager.implementation(params)
PlatformInAppLocalhostServer PlatformInterface.verify(..., _token) PlatformInAppLocalhostServer.implementation(params)
PlatformNavigationDelegate token passed by subclass PlatformNavigationDelegate({required super.token})

Sources: platform_inappwebview_controller.dart, platform_cookie_manager.dart, platform_in_app_localhost_server.dart, platform_navigation_delegate.dart

Creation Parameters and the Extension Rule

Section titled “Creation Parameters and the Extension Rule”

Platform packages widen the contract by subclassing the parameter object, never by mutating it. The base PlatformInAppWebViewControllerCreationParams carries only id and webviewParams; Android adds a fromPlatformInAppWebViewControllerCreationParams factory that copies the base fields forward, with an explicit avoid_unused_constructor_parameters ignore documenting that the placeholder exists to absorb future base-class fields without a break.

PlatformWebViewCreationParams<T> is the widest object in the package — a generic record of every WebView event callback, parameterized by the controller type T the platform hands back to the app. The generic parameter is how the same params class serves the widget, the headless variant, and the in-app browser: each derives a new params class that extends PlatformWebViewCreationParams and forwards the full callback list through super. named arguments, adding only its own fields (key, initialSize, webViewEnvironment, keepAlive, and so on).

Params class Adds on top of PlatformWebViewCreationParams
PlatformInAppWebViewWidgetCreationParams key, layoutDirection, gestureRecognizers, headlessWebView, keepAlive, preventGestureDelay, webViewEnvironment
PlatformHeadlessInAppWebViewCreationParams initialSize (default Size(-1, -1)), webViewEnvironment, onEvicted
AndroidInAppWebViewControllerCreationParams Nothing yet — pure forwarder, ready for future base fields

Sources: platform_inappwebview_controller.dart, in_app_webview_controller.dart, platform_webview.dart, platform_inappwebview_widget.dart, platform_headless_in_app_webview.dart

The interface’s second job — after factories — is to define exactly what a Dart object looks like once serialized. URLRequest is representative: the abstract declaration carries WebUri, Uint8List, Map, and enum-typed getters with @JsonKey converters, and the generated concrete class turns those into final fields with a fromJson factory, copyWith, and field-addressable patching.

classDiagram
class URLRequest_abstract["$URLRequest (declared)"] {
+WebUri? url
+Uint8List? body
+URLRequestCachePolicy? cachePolicy
+double? timeoutInterval
}
class URLRequest_generated["URLRequest (generated)"] {
+factory fromJson(Map)
+toJson()
+copyWith()
+copyWithField()
}
class URLRequestPatch["URLRequestPatch extends PatchBase"]
class URLRequestFields["URLRequestFields (abstract final)"]
URLRequest_abstract --> URLRequest_generated : zorphy generates
URLRequest_generated --> URLRequestPatch
URLRequest_generated --> URLRequestFields

Sources: url_request.dart, url_request.zorphy.dart, url_request.zorphy.dart

Two details of the generated shape matter for anyone touching the seam. First, immutability is real: every field is final and all mutation flows through copyWith, so a settings object handed to a platform implementation cannot be changed underneath it. Second, patch types and field descriptors are emitted alongside the entity, which is what lets callers write copyWithField(URLRequestFields.url, ...) without stringly-typed field names.

Sources: url_request.zorphy.dart, webview_package_info.zorphy.dart

Enums are the one place where the generated .index is not trustworthy. Where the native side historically used a non-sequential integer _value, the package keeps a plain Dart enum plus an explicit lookup table and a pair of conversion functions, and the export barrel names those functions so no caller can accidentally rely on ordinal positions.

Enum Wire values Why a table is required
CacheMode -1, 1, 2, 3 Gaps and a negative sentinel; .index would be wrong
URLRequestNetworkServiceType non-sequential Preserved legacy native _value
HTTPCookieSameSitePolicy via httpCookieSameSitePolicyFromWire Referenced from generated Cookie converters
WebAuthenticationSupport via webAuthenticationSupportToWire Referenced from generated settings converters

Sources: cache_mode.dart, url_request.dart, cookie.dart, in_app_webview_settings.dart

A few contract types are hand-written because they are not data records. WebUri implements Uri while retaining the original raw string, and exposes forceToStringRawValue specifically because toString() is the serialization path to the native side — a subtle but load-bearing detail for non-standard schemes. Color_ exists solely so the analyzer accepts Color inside generated entities, and ChannelController is the mixin every native controller uses to hold its MethodChannel and assert against use-after-dispose.

Sources: web_uri.dart, util.dart, color_serialization_test.dart

Domain Delegates: Splitting Without Breaking

Section titled “Domain Delegates: Splitting Without Breaking”

The controller contract is 2,551 lines. Rather than growing further, the interface splits it behind four optional delegates — navigation, JavaScript, cookies, settings — each itself a PlatformInterface with its own token. The compatibility trick is that the base getters return null, so an implementation written before the split still compiles and behaves exactly as before; the compile-time probe test pins both the delegate types and the four getters so drift fails flutter analyze rather than a user’s build.

Delegate Contract surface Default on base class
PlatformNavigationDelegate getUrl, getTitle, getProgress, loadUrl, postUrl, loadData, loadFile, reload, history ops, isLoading, stopLoading null
PlatformJavaScriptDelegate evaluateJavascript, callAsyncJavaScript, script/style injection, handler add/remove null
PlatformCookieDelegate setCookie, getCookies, getCookie, deleteCookie(s), getAllCookies, removeSessionCookies null
PlatformSettingsDelegate setSettings, getSettings null

Sources: platform_inappwebview_controller.dart, platform_navigation_delegate.dart, platform_settings_delegate.dart, in_app_webview_controller_delegates_test.dart

Android shows the intended implementation shape: four lazily-created delegate fields, each a thin forwarder to the controller it wraps, so behavior is byte-identical to calling the monolith while the surface is partitioned. The app-facing tier mirrors the same partition with its own four facades, which is why the split is visible from both ends of the seam and invisible in the middle of a call.

Sources: in_app_webview_controller.dart, android_navigation_delegate.dart, in_app_webview_controller.dart

Because seven packages pin this one by version (^6.7.0 in the core, in each platform package, and in the module’s override block), a breaking change here is a coordinated release of the entire monorepo. The package therefore documents an explicit preference for additive change, and the codebase shows the three sanctioned techniques: default-throwing methods, null-defaulted delegate getters, and a no-op base implementation for capabilities only some engines have (setHeadlessMaxLiveWebViews and createPlatformInAppLocalhostServer both have concrete base bodies rather than throwing).

Sources: README.md, inappwebview_platform.dart, inappwebview_platform.dart, pubspec.yaml

The umbrella package also curates what consumers see. It re-exports the entire interface but hides eight internal identifiers — ChannelController, InternalChannelController, InternalInAppWebViewKeepAlive, IdGenerator, Color_, Util, UtilColor, HexColor, MapSize, MapEdgeInsets — so the seam stays public while its plumbing does not become de facto API.

Sources: zikzak_inappwebview.dart

Two structural guards keep the contract thin. The first is documentary: SPLIT_MAP.md states that the module tier must not import platform-interface internals beyond the re-exported public facades, and lists the exact seam classes it may touch. The second is mechanical: scripts/grep_gate.sh fails the build if intelligence-layer identifiers (WebViewPool, CassetteEngine, RecipePort, NavigationTrackerPort, and their snake_case module filenames) appear in the core, and separately fails if the module imports the interface package at all.

Guard Mechanism Failure it prevents
Grep gate (core) Pattern scan over zikzak_inappwebview/lib/src with a carve-out for raw capture plumbing Policy code leaking into the thin plugin tier
Grep gate (module) Scan for zikzak_inappwebview_platform_interface under the module’s lib Module bypassing the core’s public API
Relative-import integrity Walks every lib/**/*.dart and resolves each relative import/export/part URI Shipping a package whose consumers cannot compile
Settings-layout regression Asserts the migrated entity path exists and the pre-migration path does not A codegen re-run reintroducing a stale import path

Sources: SPLIT_MAP.md, grep_gate.sh, relative_import_integrity_test.dart, in_app_webview_settings_migration_regression_test.dart

Those last two guards exist because the seam has already failed once in production: version 5.0.1 shipped a platform_settings_delegate.dart whose relative import resolved to a file the Zorphy migration had moved, and every consumer of the published package failed to compile. The analyzer can see such a directive locally, but nothing caught it before publication — hence a test that walks the filesystem rather than trusting the analyzer.

Sources: relative_import_integrity_test.dart, in_app_webview_settings_migration_regression_test.dart

The seam is best understood as the middle layer of three: what the app-facing wrappers expose above it, and how each engine satisfies it below. Continue with Monorepo Layout and the Federated Plugin Model for the package topology and release wiring, then Two-Tier Core/Module Split and the Grep Gate for the enforcement mechanism in full. For the object model behind the entities described above, see Zorphy Entity Model Layer and Code Generation; for how the abstract controller becomes four usable facades, see Domain Controller Facades: Navigation, JavaScript, Cookies, Settings. Platform-by-platform conformance is covered in Android Native Layer (Java), Apple Native Layer (Swift and Swift Package Manager), and the remaining implementation pages.