Flutter WebViewWidget inside StatefulWidget does not dispose

16 views Asked by At

On my app, i navigate to a StatefulWidget that contains a fullscreeen WebView widget like

Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => MyWebviewScreen(
              url : "someurl", 
          ),
        ),
      );

MyWebViewScreen build is like

 @override
 Widget build(BuildContext context) {
   return Scaffold(
     body: SafeArea(
       child: WebViewWidget(
         controller: WebViewController()
           ..setJavaScriptMode(JavaScriptMode.unrestricted)
           ..setBackgroundColor(const Color(0x00000000))
           ..enableZoom(false)
           ..setNavigationDelegate(
               NavigationDelegate(
                 onProgress: (int progress) {
                   // Update loading bar.
               },
               onPageStarted: (String url) {},
               onPageFinished: (String url) {},
               onWebResourceError: (WebResourceError error) {},
               onNavigationRequest: (NavigationRequest request) async {
                 if (request.url == "a condition") {
                   Navigator.pop(context);
                   return NavigationDecision.prevent;
                 }
                 return NavigationDecision.navigate;
               },
             ),
           )
           ..loadRequest(Uri.parse(widget.launchUrl)),
         ),
       ),
     );
   }

The url i open has a content that reproduce some sounds, but when Widget is closed (onNavigationRequest if clause is satisfied or user press back button on Android), i can still hear sounds from webview, like the StatefulWidget is not disposed correctly.

What's wrong?

0

There are 0 answers