randomKey static method

String randomKey({
  1. int length = 6,
  2. String? chars,
  3. List<String> ignores = const [],
  4. KeyFormats format = KeyFormats.alphabetsAndNumbers,
})

Implementation

static String randomKey({
  int length = 6,
  String? chars,
  List<String> ignores = const [],
  KeyFormats format = KeyFormats.alphabetsAndNumbers,
}) {
  String c = chars ?? format.value;
  Random r = Random.secure();
  String code = List.generate(length, (i) => c[r.nextInt(c.length)]).join();
  if (ignores.isNotEmpty && ignores.contains(code)) {
    return randomKey(length: length, ignores: ignores);
  }
  return code;
}