UUID type for Dart

CI pub package License

This package provides implementation of Universally Unique Identifier (UUID) for Dart, and supports generation, parsing and formatting of UUIDs.

Features

  • x Creates UUIDs from strings and byte arrays, including GUID and URN strings
  • x Provides access to UUID variant, version, and byte data
  • x Generates RFC 9562 versions 1, 4, 5, 6, and 7 UUIDs
  • x Implements Comparable for UUID comparison and lexicographical sorting
  • x Runs on the web, server, and Flutter

RFC version support

  • x v1, based on timestamp and MAC address
  • v2, based on timestamp, MAC address and POSIX UID/GID (DCE 1.1) Not planned
  • v3, based on MD5 hashing Not planned
  • x v4, based on random numbers
  • x v5, based on SHA-1 hashing
  • x v6, a time-ordered reordering of UUID version 1
  • x v7, a Unix Epoch time-based UUID
  • v8, A free-form UUID format which has no explicit requirements except maintaining backward compatibility.

Requirements

  • Dart SDK ^3.8.0
  • crypto package

Getting Started

Installation

  1. Add an entry in your pubspec.yaml for uuid_type
dependencies:
  uuid_type: ^2.2.0
  1. Run pub get (flutter packages get for Flutter)
  2. Import
import 'package:uuid_type/uuid_type.dart';

Usage

Generate UUIDs

import 'package:uuid_type/uuid_type.dart';

void main() {
  var u = TimeUuidGenerator().generate();
  print(u.toString());

  u = NameUuidGenerator(NameUuidGenerator.urlNamespace).generateFromString('https://dart.dev/');
  print(u.toString());

  u = RandomUuidGenerator().generate();
  print(u.toString());
}

See more examples and documentation.

Release notes

See CHANGELOG

Features and Bugs

Please file bugs and feature requests at the issue tracker.

Libraries

uuid_type