Skip to content
pubscout

cuid2

4.1.0, released 9 months ago by obsidia.io

Generate collision‑resistant, URL‑friendly IDs with optional secure randomness

WASM-ready
$ flutter pub add cuid2
Source repository

What it does

Cuid2 creates unique identifiers that are hard to guess, collision‑resistant, and suitable for horizontal scaling. It uses cryptographically secure hashing and multiple entropy sources.

AI-written summary of version 4.1.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • Need globally unique IDs without coordination
  • Require IDs that are URL and name friendly
  • Need offline ID generation
  • Want to avoid UUID collisions in large distributed systems

Skip it when

  • Need sequential or sortable IDs
  • Running in tight render loops where performance is critical

Strengths

  • High collision resistance
  • Secure RNG support
  • Fast and synchronous API
  • No async overhead

Weaknesses

  • Not suitable for sequential IDs
  • Can be slower than simple counters in tight loops
  • Requires Dart SDK >=3.4.0
  • No built‑in CLI support before v4.0.0

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
2

Add dependency in pubspec and import 'package:cuid2/cuid2.dart'; no extra permissions or build steps

import 'package:cuid2/cuid2.dart';

void main() {
  final id = cuid();
  final secureId = cuidSecure(30);
  print(id);
  print(secureId);
}

Works with

Packages commonly used together with cuid2: ones it builds on, ones built on it, and its own family.