Skip to content
pubscout

nanoid2

2.1.0, released 3 months ago by pascalwelsch.com

A tiny, secure, URL-friendly, unique string ID generator with a pure Dart API.

WASM-ready
$ flutter pub add nanoid2
Source repository

What it does

Generates unique string IDs using a customizable length and alphabet. Supports secure random generation out of the box and various predefined alphabets like URL-safe, lowercase, uppercase, numbers, and base58.

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

Use it when

  • You need to generate unique identifiers or IDs for database records.
  • You need URL-friendly or custom-alphabet string IDs with a specific collision resistance.

Skip it when

  • You specifically require sequential integer IDs (e.g., auto-incrementing database keys).

Strengths

  • Pure Dart API with zero dependencies.
  • Highly configurable length and numerous built-in alphabets (base58, crockfordBase32, cookieSafe, etc.).
  • Uses cryptographically secure random number generators by default.

Weaknesses

  • Lacks an asynchronous API out of the box (though it can be wrapped in a Future if needed).

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
0
import 'package:nanoid2/nanoid2.dart';

void main() {
  final id = nanoid(); 
  // => LXL0J9b-Uj1C0sZH837Fk
}

Alternatives

Packages that do the same job and could replace nanoid2.

  • uuid

    If you strictly need standard UUIDs (v1, v4, v5) instead of customizable compact string IDs.

Works with

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