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.
Libraries
- unique_id_dart
- Support for doing something awesome.