Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The class 'WebViewController' doesn't have an unnamed constructor

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'.
like image 638
Ahmed Wagdi Avatar asked Feb 19 '26 13:02

Ahmed Wagdi


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:

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)


like image 182
Turkey Avatar answered Feb 26 '26 10:02

Turkey


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.

like image 27
MendelG Avatar answered Feb 26 '26 09:02

MendelG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!