onDownloadStart method

  1. @override
void onDownloadStart(
  1. String url,
  2. String userAgent,
  3. String contentDisposition,
  4. String mimetype,
  5. int contentLength,
)

Notify the host application that a file should be downloaded.

Implementation

@override
void onDownloadStart(
  String url,
  String userAgent,
  String contentDisposition,
  String mimetype,
  int contentLength,
) {
  if (_onNavigationRequest == null) {
    return;
  }

  final FutureOr<bool> returnValue = _onNavigationRequest!(
    url: url,
    isForMainFrame: true,
  );

  if (returnValue is bool && returnValue) {
    loadUrl(url, <String, String>{});
  } else {
    (returnValue as Future<bool>).then((bool shouldLoadUrl) {
      if (shouldLoadUrl) {
        loadUrl(url, <String, String>{});
      }
    });
  }
}