openWebActivity static method

Future<void> openWebActivity(
  1. String url, {
  2. String? title,
  3. Map<String, String>? headers,
  4. InterceptUrlCallBack? callback,
})

打开简单的x5webview

Implementation

static Future<void> openWebActivity(String url,
    {String? title,
    Map<String, String>? headers,
    InterceptUrlCallBack? callback}) async {
  if (defaultTargetPlatform == TargetPlatform.android) {
    final Map<String, dynamic> params = <String, dynamic>{
      'title': title ?? "",
      'url': url,
      'headers': headers ?? {},
      'isUrlIntercept': callback != null
    };
    if (callback != null) {
      _channel.setMethodCallHandler((call) async {
        try {
          if (call.method == "onUrlLoad") {
            print("onUrlLoad----${call.arguments}");
            Map arg = call.arguments;
            callback(arg["url"], Map<String, String>.from(arg["headers"]));
          }
        } catch (e) {
          print(e);
        }
      });
    }

    return await _channel.invokeMethod("openWebActivity", params);
  } else {
    return;
  }
}