I am working on a flutter app in which I am using flutter_inappwebview. In my website, after navigating to 3-4 pages, there are some pdf download buttons which have a direct pdf link. When I'm clicking on any first button, the app does nothing but registers a touch and gives this output:

I/ViewRootImpl@fd31adfMainActivity: ViewPostIme pointer 0

I/ViewRootImpl@fd31adfMainActivity: ViewPostIme pointer 1

When I click on any button again, I get this in the console:

W/chromium(27451): [WARNING:aw_contents.cc(1108)] Blocking popup window creation as an outstanding popup window is still pending.

I don't know why I am getting this even when I have tried all the solutions.

Note: I'm facing this issue in Android only, it is working fine in iOS.

This is the code of my application:


import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:in_app_update/in_app_update.dart';
import 'package:path_provider/path_provider.dart';
import 'package:url_launcher/url_launcher.dart';

class Home1 extends StatefulWidget {
  const Home1({super.key});

  @override
  State<Home1> createState() => _Home1State();
}

class _Home1State extends State<Home1> {

  InAppWebViewController? webViewController;
  bool isLoading = true;

  @override
  void initState() {
    super.initState();
    checkForUpdate();
  }

  Future<void> checkForUpdate() async {
    InAppUpdate.checkForUpdate().then((info) {
      setState(() {
        if (info.updateAvailability == UpdateAvailability.updateAvailable) {
          if (info.immediateUpdateAllowed) {
            if (kDebugMode) {
              print('Update Available');
            }
            InAppUpdate.performImmediateUpdate();
          }
        }
      });
    }).catchError((e) {
      if (kDebugMode) {
        print(e.toString());
      }
    });
  }

  /// Method to download the pdf file to the external storage.
  Future<void> downloadFile(String url) async {
    final directory = await getApplicationDocumentsDirectory();
    await FlutterDownloader.enqueue(
      url: url,
      savedDir: directory.path,
      showNotification: true,
      openFileFromNotification: true,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Builder(builder: (BuildContext context) {
          return WillPopScope(
            onWillPop: () async {
              if (webViewController != null) {
                if (await webViewController!.canGoBack()) {
                  webViewController!.goBack();
                  return Future.value(false);
                }
              }
              return Future.value(true);
            },
            child: Scaffold(
              body: SafeArea(
                child: Stack(
                  children: [
                    InAppWebView(
                      initialUrlRequest: URLRequest(
                        url: Uri.parse(initialUrl),
                        headers: {
                          'Content-Security-Policy': 'default-src \'self\';',
                          'X-content-type-options': 'nosniff'
                        }
                      ),
                      initialOptions: InAppWebViewGroupOptions(
                        crossPlatform: InAppWebViewOptions(
                          useShouldOverrideUrlLoading: true,
                          mediaPlaybackRequiresUserGesture: false,
                          javaScriptEnabled: true,
                          useOnDownloadStart: true,
                          javaScriptCanOpenWindowsAutomatically: true,
                          allowFileAccessFromFileURLs: true,
                          allowUniversalAccessFromFileURLs: true,
                          cacheEnabled: true,
                          useOnLoadResource: true,
                        ),
                        android: AndroidInAppWebViewOptions(
                          useHybridComposition: true,
                          useWideViewPort: false,
                          builtInZoomControls: false,
                          domStorageEnabled: true,
                          supportMultipleWindows: true,
                          allowFileAccess: true,
                          allowContentAccess: true,
                          databaseEnabled: true,
                          hardwareAcceleration: true,
                        )
                      ),
                      shouldOverrideUrlLoading: (controller, action) {
                        print("override");
                        return Future.value(NavigationActionPolicy.ALLOW);
                      },
                      onLoadResource: (controller, resource) async {
                        if (resource.url != null && resource.url.toString().endsWith('.pdf')) {
                          try {
                            await launch(resource.url.toString());
                          } catch (e) {
                            print("Error launching PDF: $e");
                          }
                        }
                      },
                      onDownloadStartRequest: (controller, uri) {
                        print(uri.toString());
                        print("download");
                        launch(uri.toString());
                      },
                      onWebViewCreated: (controller) {
                        webViewController = controller;
                      },
                      onLoadStart: (controller, uri) async {
                        setState(() {
                          isLoading = true;
                        });

                        if (uri != null && uri.toString().endsWith('.pdf')) {
                          try {
                            await launch(uri.toString());
                            downloadFile(uri.toString());
                            setState(() {
                              isLoading = false;
                            });
                          } catch (e) {
                            if (kDebugMode) {
                              print("Error launching PDF: $e");
                            }
                          }
                        }
                      },
                      onLoadStop: (controller, url) {
                        setState(() {
                          isLoading = false; // Stop loading, hide the loader
                        });
                      },
                      onLoadError: (controller, url, code, message) {
                        if (kDebugMode) {
                          print("Error loading: $message, error code: $code");
                        }
                      },
                    ),
                    if (isLoading)
                      const Center(
                        child: CircularProgressIndicator(),
                      ),
                  ],
                )
              ),
            ),
          );
        }),
      );
  }
}```
0

There are 0 answers