I am trying to display a web view in Flutter for Web but I got the following error :
PlatformException(Unregistered factory, No factory registered for viewty
Answer by @mohamed-salah is helpful, however, I was only getting a loading symbol on my screen. We need put webview
inside WillPopScope
widget. Use the following code to properly load webview
-
In pubspec.yaml
add dependency
flutter_webview_plugin: ^0.3.9+1 // replace with latest version
In StatefulWidget
class, use following code -
class _WebViewLoadingState extends State {
final _webViewPlugin = FlutterWebviewPlugin();
@override
void initState() {
// TODO: implement initState
super.initState();
// on pressing back button, exiting the screen instead of showing loading symbol
_webViewPlugin.onDestroy.listen((_) {
if (Navigator.canPop(context)) {
// exiting the screen
Navigator.of(context).pop();
}
});
}
@override
Widget build(BuildContext context) {
// WillPopScope will prevent loading
return WillPopScope(
child: WebviewScaffold(
url: "https://www.google.com",
withZoom: false,
withLocalStorage: true,
withJavascript: true,
appCacheEnabled: true,
appBar: AppBar(
title: Text("Browser"),
),
),
onWillPop: () {
return _webViewPlugin.close();
}
);
}
}