newKey top-level property

String get newKey

Returns a 32-character random key made of digits, lowercase and uppercase Latin letters. Handy for generating string-typed primary keys.

Implementation

String get newKey {
  const String alphabet =
      '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  final Random rng = Random.secure();
  final StringBuffer buffer = StringBuffer();
  for (int i = 0; i < 32; i++) {
    buffer.write(alphabet[rng.nextInt(alphabet.length)]);
  }
  return buffer.toString();
}