removeUserScript method Null safety

Future<bool> removeUserScript(
  1. {required UserScript userScript}

Removes the specified userScript from the webpage’s content. User scripts already loaded into the webpage's content cannot be removed. This will have effect only on the next page load. Returns true if userScript was in the list, false otherwise.

NOTE for iOS: this method will throw an error if the WebView.windowId has been set. There isn't any way to add/remove user scripts specific to iOS window WebViews. This is a limitation of the native iOS WebKit APIs.


Future<bool> removeUserScript({required UserScript userScript}) async {
  assert(_webview?.windowId == null ||
      defaultTargetPlatform != TargetPlatform.iOS);

  var index = _userScripts.indexOf(userScript);
  if (index == -1) {
    return false;

  Map<String, dynamic> args = <String, dynamic>{};
  args.putIfAbsent('userScript', () => userScript.toMap());
  args.putIfAbsent('index', () => index);
  await _channel.invokeMethod('removeUserScript', args);

  return true;