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'.
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:
flutter pub upgrade
(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)
For me, the problem was that I was using an older version of the package.
I needed to manually enter the correct version in the pubspec.yaml file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With