saveWebArchive method Null safety

Future<String?> saveWebArchive(
  1. {required String filePath,
  2. bool autoname = false}
)

Saves the current WebView as a web archive. Returns the file path under which the web archive file was saved, or null if saving the file failed.

filePath represents the file path where the archive should be placed. This value cannot be null.

autoname if false, takes filePath to be a file. If true, filePath is assumed to be a directory in which a filename will be chosen according to the URL of the current page.

NOTE for iOS: Available on iOS 14.0+. If autoname is false, the filePath must ends with the WebArchiveFormat.WEBARCHIVE file extension.

NOTE for Android: if autoname is false, the filePath must ends with the WebArchiveFormat.MHT file extension.

Official Android API: https://developer.android.com/reference/android/webkit/WebView#saveWebArchive(java.lang.String,%20boolean,%20android.webkit.ValueCallback%3Cjava.lang.String%3E)

Implementation

Future<String?> saveWebArchive(
    {required String filePath, bool autoname = false}) async {
  if (!autoname) {
    if (defaultTargetPlatform == TargetPlatform.android) {
      assert(filePath.endsWith("." + WebArchiveFormat.MHT.toValue()));
    } else if (defaultTargetPlatform == TargetPlatform.iOS) {
      assert(filePath.endsWith("." + WebArchiveFormat.WEBARCHIVE.toValue()));
    }
  }

  Map<String, dynamic> args = <String, dynamic>{};
  args.putIfAbsent("filePath", () => filePath);
  args.putIfAbsent("autoname", () => autoname);
  return await _channel.invokeMethod('saveWebArchive', args);
}