makeController static method
- void onPageStarted(
- String url
- void onPageFinished(
- String url
- void onProgress(
- int progress
- void onUrlChange(
- UrlChange change
- void onWebResourceError(
- WebResourceError
- void onHttpError(
- HttpResponseError error
- void onHttpAuthRequest(
- HttpAuthRequest request
- VoidCallback? onCloseRequested,
Creates a WebViewController with the Fanmeter JavaScript bridge
(window.FanmeterBridge) installed by the native SDK.
The app keeps full ownership of the WebView: it still loads the URL and still
places the WebViewWidget in its own widget tree. Only the bridge is native.
Await this before calling WebViewController.loadRequest — the bridge is
injected as a document-start user script, which only applies to page loads
started after it is installed.
Optional parameters allow the client to extend behaviour without interfering with the bridge:
onPageStarted: called when a page starts loading.onPageFinished: called on each page load.onProgress: called with the load progress, from 0 to 100.onNavigationRequest: controls whether navigation to a URL should proceed.onUrlChange: called when the WebView moves to a new URL.onWebResourceError: called when a web resource error occurs.onHttpError: called when a resource comes back with an HTTP error status.onHttpAuthRequest: called when the page requests HTTP authentication.onCloseRequested: called when the web layer asks to close the screen hosting the WebView (window.FanmeterBridge.closeWebView()).
These mirror NavigationDelegate's own callbacks, with the exception of
onSslAuthError: its SslAuthError type is not exported by
package:webview_flutter/webview_flutter.dart, so exposing it would mean
depending on the platform interface package directly.
Note: do not call WebViewController.enableZoom on the returned controller.
It resets the WebView's user scripts, which would remove the native bridge.
For the same reason, do not call WebViewController.setNavigationDelegate
on it either — on Android that replaces the native WebViewClient, and with
it the SDK's protection against the WebView killing the app process (and the
running service with it) when the system reclaims its renderer. Pass the
callbacks above instead.
Example usage:
final controller = await FanmeterWebInterface.makeController();
controller.loadRequest(Uri.parse('https://your-fanzone-url.com'));
// In your widget tree:
WebViewWidget(controller: controller)
Implementation
static Future<WebViewController> makeController({
void Function(String url)? onPageStarted,
void Function(String url)? onPageFinished,
void Function(int progress)? onProgress,
FutureOr<NavigationDecision> Function(NavigationRequest)? onNavigationRequest,
void Function(UrlChange change)? onUrlChange,
void Function(WebResourceError)? onWebResourceError,
void Function(HttpResponseError error)? onHttpError,
void Function(HttpAuthRequest request)? onHttpAuthRequest,
VoidCallback? onCloseRequested,
}) async {
final controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted);
// Awaited, and not part of the cascade above, so the native WebViewClient this installs is
// already in place when the SDK wraps it below - one set afterwards replaces the wrapper.
await controller.setNavigationDelegate(NavigationDelegate(
onPageStarted: onPageStarted,
onPageFinished: onPageFinished,
onProgress: onProgress,
onNavigationRequest: onNavigationRequest,
onUrlChange: onUrlChange,
onWebResourceError: onWebResourceError,
onHttpError: onHttpError,
onHttpAuthRequest: onHttpAuthRequest,
));
// Hand the underlying native WebView to the SDK's own FanmeterWebInterface,
// which installs the bridge on it and owns every callback from then on.
await FanmeterPlatform.instance.attachWebInterface(
_webViewIdentifier(controller),
onCloseRequested,
);
return controller;
}