sdkCallback static method

void sdkCallback({
  1. dynamic onSDKTokenAuthSuccess,
  2. dynamic onSDKTokenUpdate,
  3. dynamic onSDKTokenAuthFailure,
  4. dynamic onVerifySuccess,
  5. dynamic onHalfwayVerifySuccess,
  6. dynamic onVerifyFailed,
  7. dynamic onTemplateFinish,
  8. dynamic onGetPhoneNumber,
  9. dynamic onProtocolClick,
  10. dynamic onVerifyInterrupt,
  11. dynamic onAuthEvent,
})

Implementation

static void sdkCallback(
    {onSDKTokenAuthSuccess,
    onSDKTokenUpdate,
    onSDKTokenAuthFailure,
    onVerifySuccess,
    onHalfwayVerifySuccess,
    onVerifyFailed,
    onTemplateFinish,
    onGetPhoneNumber,
    onProtocolClick,
    onVerifyInterrupt,
    onAuthEvent}) {
  _methodChannel.setMethodCallHandler((call) async {
    final AuthResponseModel responseModel = AuthResponseModel.fromJson(
      Map.from(call.arguments),
    );
    switch (call.method) {
      case 'onSDKTokenAuthSuccess':
        // token鉴权成功
        await onSDKTokenAuthSuccess();
        break;
      case 'onSDKTokenUpdate':
        // 获取新Token
        return await onSDKTokenUpdate();
      case 'onSDKTokenAuthFailure':
        // token鉴权失败
        await onSDKTokenAuthFailure(responseModel);
        break;
      case 'onVerifySuccess':
        // 认证成功
        onVerifySuccess(responseModel);
        break;
      case 'onHalfwayVerifySuccess':
        // 中途认证节点
        onHalfwayVerifySuccess(responseModel);
        break;
      case 'onVerifyFailed':
        // 认证失败
        onVerifyFailed(responseModel);
        break;
      case 'onTemplateFinish':
        // 场景流程结束
        onTemplateFinish(responseModel);
        break;
      case 'onGetPhoneNumber':
        // 填充手机号
        return onGetPhoneNumber();
      case 'onProtocolClick':
        // 点击协议富文本
        onProtocolClick(responseModel);
        break;
      case 'onVerifyInterrupt':
        // 认证中断
        onVerifyInterrupt(responseModel);
        break;
      case 'onAuthEvent':
        // 场景事件回调
        onAuthEvent(responseModel);
        break;
      default:
        throw UnsupportedError('Unrecognized JSON message');
    }
  });
}