I have a problem with my flutter app using the package webview_flutter , here Is my code:
pubspec.yaml
webview_flutter: ^4.0.6
dart
WebViewController breachWebViewController = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setBackgroundColor(const Color(0x00000000))
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {
// Update loading bar.
},
onPageStarted: (String url) {},
onPageFinished: (String url) {},
onWebResourceError: (WebResourceError error) {},
onNavigationRequest: (NavigationRequest request) {
if (request.url.startsWith('https://www.youtube.com/')) {
return NavigationDecision.prevent;
}
return NavigationDecision.navigate;
},
),
)
..loadRequest(Uri.parse('https://flutter.dev'));
but I am getting this error :
The class 'WebViewController' doesn't have an unnamed constructor.
Try using one of the named constructors defined in 'WebViewController'.
2
Answers
I just got this problem as a result of someone else having upgraded
webview_flutter
to a newer version.(The constructor changed in the major version change from 3 to 4 for this module).
To update this dependency to the correct version in my environment I needed to do:
(And in my case it was a sub module, not the main app – I needed to go into the module that used
webview_flutter
and run that command there)Based on the library example project you have to initialize the controller in this way, taken from here https://pub.dev/packages/webview_flutter/example: