secureRandomString function
Cryptographically random token of length URL-safe alphanumeric chars
(Laravel Str::random).
Implementation
String secureRandomString(int length) {
const alphabet =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
final random = Random.secure();
return String.fromCharCodes(
List<int>.generate(
length,
(_) => alphabet.codeUnitAt(random.nextInt(alphabet.length)),
),
);
}