Ulid class final
Generates ULIDs: 48 bits of timestamp followed by 80 bits of randomness, rendered as 26 characters of Crockford base-32.
final ids = Ulid();
ids.generate(); // 01JQ8XKF2M7YB4C3D5E6F7G8H9
Within a single millisecond the random component is incremented rather than redrawn, so identifiers minted in the same tick remain strictly increasing. If the system clock moves backwards — a network time correction, a user changing the device clock — generation continues from the last issued timestamp instead of emitting an identifier that sorts before its predecessor. Monotonicity of the identifier sequence is preserved at the cost of the embedded timestamp briefly running ahead of the wall clock, which is the right trade: the identifier is an ordering key first and a timestamp second.
The random component is drawn from Random and is not a security token.
If an identifier must be unguessable — a share link, a session key — pass
Random.secure() explicitly and accept the throughput cost.
- Implemented types
- Available extensions
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
-
generate(
) → String -
Returns a new identifier.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
prefixed(
String prefix) → String -
Available on IdGenerator, provided by the PrefixedIds extension
Returns<prefix>_<id>. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
timestampOf(
String ulid) → DateTime? -
Recovers the creation timestamp embedded in
ulid.
Constants
- alphabet → const String
-
Crockford's base-32 alphabet: no
I,L,OorU, so a hand-transcribed identifier cannot be corrupted by the usual confusions. - length → const int
- Total length of a rendered ULID.
- randomLength → const int
- Number of characters encoding the random component.
- timeLength → const int
- Number of characters encoding the millisecond timestamp.