IdGenerator class

Public API for generating IDs and reversible encodings.

All methods use Dart's non-cryptographic Random. They are safe for database keys, slugs, and display identifiers, but not for tokens, session keys, password-reset links, or any value an attacker must not be able to guess. Use SecureIdGenerator for those cases.

Constructors

IdGenerator()

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

decodeFromBase64(String encoded) → List<Object?>
Decodes a Base64 string produced by encodeToBase64 back to a list.
encodeToBase64(List<Object?> objects) → String
Encodes a list of objects to a Base64 string after JSON serialization.
nanoid({int size = 21, String? alphabet}) → String
Generates a nanoid-style random ID.
prefixed(String prefix, {int length = 16}) → String
Generates a prefixed ID in the style prefix_xxxx (e.g. cus_Xk3mQ9).
randomString({int length = 8, bool useLetters = true, bool useNumbers = true, bool useSymbols = true}) → String
Generates a random string with configurable character sets.
shortId({int length = 8}) → String
Generates a short URL-safe alphanumeric ID (letters + digits, no symbols).
timestampId() → String
Generates a timestamp-based ID with prefix G.
ulid() → String
Generates a ULID — a 26-character, lexicographically sortable ID.
ulidMonotonic() → String
Generates a ULID that sorts after every ULID this generator produced before it, including within the same millisecond.
uuidV4Like() → String
Generates a UUID v4-shaped random ID.