flutterwebviewmigrationcode-documentation

webview_flutter migration V4 Doc


How do I make my current code compatible with V4 update I checked their documentation but I couldn't follow along

final Completer<WebViewController> _controller = Completer<WebViewController>();
WebView.platform = SurfaceAndroidWebView();

WebView(
        initialUrl: widget.url,
        javascriptMode: JavascriptMode.unrestricted,
        onWebViewCreated: (WebViewController webViewController) {
          _controller.complete(webViewController);
        },
       navigationDelegate: (NavigationRequest request) {}
        onProgress: (progress) {},
        gestureNavigationEnabled: true,
      ),

Solution

  • Solved :

      WebViewController controller = WebViewController();
    
        controller = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..setBackgroundColor(const Color(0x00000000))
      ..loadRequest(Uri.parse(widget.url))
      ..setNavigationDelegate(NavigationDelegate(
        onProgress: (progress) {
          if (progress >= 100) {
            setState(() {
              isLoading = false;
            });
          }
        },
      ));
    
     WebViewWidget(controller: controller)