generateId static method
Generate a random alphanumeric ID
Useful for generating unique identifiers for temporary elements.
Example:
final id = FSUtils.generateId(length: 12);
Implementation
static String generateId({int length = 8}) {
assert(length > 0, 'Length must be positive');
const chars =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
final random = Random.secure();
return String.fromCharCodes(
Iterable.generate(
length,
(_) => chars.codeUnitAt(random.nextInt(chars.length)),
),
);
}