setCacheUrlHashCallback static method

Future<void> setCacheUrlHashCallback(
  1. dynamic getUrlHashCallback(
    1. String
    )
)

设置加载url的hash值回调。如果不设置,SDK使用md5算法。

Implementation

static Future<void> setCacheUrlHashCallback(
    Function(String) getUrlHashCallback) async {
  const BasicMessageChannel<String> _basicMessageChannel =
      BasicMessageChannel<String>(
    "getUrlHashCallback",
    StringCodec(),
  );
  // 注册调用 Flutter 端的 callback, 并发送至 Native 端
  _basicMessageChannel.setMessageHandler((message) async {
    if (message != null) {
      Map<String, dynamic> parsedArguments = jsonDecode(message);
      String url = parsedArguments["param1"];
      String result = getUrlHashCallback(url);
      // 处理接收到的消息
      return result; // 返回结果给 Native
    }
    return "";
  });

  try {
    await methodChannel.invokeMethod('setCacheUrlHashCallback');
  } on PlatformException catch (e) {
    print("Failed to register callback: '${e.message}'.");
  }
}