generateUserData static method

String generateUserData({
  1. String? methodName,
})

Implementation

static String generateUserData({
  String? methodName,
}) {
  String trace = StackTrace.current.toString();
  RegExp exp = RegExp(r'IMNative.[a-zA-Z_0-9]+\s');
  Iterable<Match> matches = exp.allMatches(trace);
  String apiName = methodName ?? "";
  String userdata = "";
  if (apiName.isEmpty) {
    for (final Match m in matches) {
      String match = m[0]!;
      if (match.isNotEmpty) {
        apiName = match.replaceAll("IMNative.", "").replaceAll(" ", "");
        break;
      }
    }
  }

  if (apiName.isNotEmpty) {
    int now = DateTime.now().microsecondsSinceEpoch;
    autoInrecKey = autoInrecKey + 1;
    userdata = "$apiName-$now-$autoInrecKey";
  } else {
    throw "get userData error trace: $trace";
  }
  return userdata;
}