Search packages, repositories and app categories

nanoid cover
Package detailsv1.0.0

nanoid

A tiny, secure, URL-friendly, unique string ID generator. Dart implementation of ai/nanoid

AndroidiOSWebmacOSWindowsLinux
30-day downloads
115K
Likes
125
Pub points
150

Install package

flutter pub add nanoid

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A lightweight, secure, and URL-friendly unique ID generator for Dart, inspired by the popular JavaScript library. It produces cryptographically strong, random strings that are safe for use in URLs, filenames, and database keys. The Dart implementation ensures cross-platform compatibility across Android, iOS, Web, macOS, Windows, and Linux. Designed for simplicity and performance, it avoids predictable patterns while maintaining minimal code size. Ideal for generating short, unique identifiers in applications requiring security and reliability.

Use cases

  • Generating unique IDs for database records
  • Creating secure tokens for authentication
  • Producing URL-safe identifiers for web routing
  • Using in distributed systems for collision-resistant keys
  • Building short, readable identifiers for user-facing content

Key features

  • Cryptographically secure random generation
  • URL-safe character set
  • Minimal code footprint
  • Cross-platform support
  • Customizable ID length
  • No external dependencies

Suitable for

  • Web and mobile app developers
  • Backend services needing unique keys
  • Applications requiring secure token generation
  • Projects prioritizing small bundle size
  • Developers using Flutter with security needs

Considerations

  • Not suitable for sequential or predictable ID requirements
  • Length must be balanced between uniqueness and readability
  • May require seeding for deterministic testing
  • Limited to string output format
  • Does not provide UUID or other ID standards

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

nanoid

pub test

Dart implementation of ai/nanoid

Installation

Add nanoid as a dependency in your pubspec.yaml file

Usage

Normal
import 'package:nanoid/nanoid.dart';

void main() {
  var id = nanoid();
  var custom_length_id = nanoid(10);
  // ...
}
Custom Alphabet or length
import 'package:nanoid/nanoid.dart';

void main() {
  var id = customAlphabet('1234567890abcdef', 10);
  // ...
}
Async API
import 'package:nanoid/async.dart';

void main() async {
  var id = await nanoid();
  var custom_length_id = await nanoid(10);
  // ...
}
Non-secure API
import 'package:nanoid/non_secure.dart';

void main() {
  var non_secure_id = nanoid();
  var custom_length_id = nanoid(10);
  // ...
}

License

MIT

Categories

Source repository

Projects using this package