unique_id_dart 1.0.0
unique_id_dart: ^1.0.0 copied to clipboard
Generate unique IDs in Dart using Snowflake or UUID v4.
unique_id_dart #
English | δΈζ
Generate unique IDs in Dart using two strategies:
- Short numeric IDs based on Snowflake.
- Standard UUID v4 strings.
Getting started #
Add the dependency:
dependencies:
unique_id_dart: ^1.0.0
Then run:
dart pub get
Usage #
import 'package:unique_id_dart/unique_id_dart.dart';
void main() {
final shortId = uniqueId();
final longId = uniqueId(shorter: false);
print(shortId);
print(longId);
}
API #
uniqueId({bool shorter = true})true(default): Snowflake-based numeric ID.false: UUID v4 string.
Notes #
- Snowflake uses a fixed
workerIdanddatacenterIdinternally. If you need multi-node uniqueness guarantees, consider exposing configuration or forking. - Run tests with
dart test. Seeexample/for a runnable demo.