randomKey static method
String
randomKey({
- int length = 6,
- String? chars,
- List<
String> ignores = const [], - 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;
}