getHitTestResult method Null safety

Future<InAppWebViewHitTestResult?> getHitTestResult()

Gets the hit result for hitting an HTML elements.

NOTE: On iOS it is implemented using JavaScript.

Official Android API: https://developer.android.com/reference/android/webkit/WebView#getHitTestResult()

Implementation

Future<InAppWebViewHitTestResult?> getHitTestResult() async {
  Map<String, dynamic> args = <String, dynamic>{};
  Map<dynamic, dynamic>? hitTestResultMap =
      await _channel.invokeMethod('getHitTestResult', args);

  if (hitTestResultMap == null) {
    return null;
  }

  hitTestResultMap = hitTestResultMap.cast<String, dynamic>();

  InAppWebViewHitTestResultType? type =
      InAppWebViewHitTestResultType.fromValue(
          hitTestResultMap["type"]?.toInt());
  String? extra = hitTestResultMap["extra"];
  return InAppWebViewHitTestResult(type: type, extra: extra);
}