### Install dart-uuid Package Source: https://pub.dev/packages/uuid/versions/0 To use the uuid package, add it to your project's pubspec.yaml file under dependencies. After adding the dependency, run 'pub install' in your project's root folder. ```yaml dependencies: uuid: 0.5.0 ``` -------------------------------- ### Initialize uuid Generator in Dart Source: https://pub.dev/packages/uuid/versions/1 Demonstrates the basic initialization of the Uuid generator in Dart. After adding the package as a dependency, you can import it and create an instance of the Uuid class to start generating IDs. ```dart import 'package:uuid/uuid.dart'; var uuid = new Uuid(); ``` -------------------------------- ### Initialize UUID Generator in Dart Source: https://pub.dev/packages/uuid/versions/0 Import the uuid package and create an instance of the Uuid class to start generating UUIDs. This is the initial step before calling any UUID generation methods. ```dart import 'package:uuid/uuid.dart'; var uuid = new Uuid(); ``` -------------------------------- ### Generate v5 UUID with namespace and name Source: https://pub.dev/packages/uuid/versions/1 Generates a v5 UUID based on a given namespace and name. This is useful for creating consistent UUIDs for specific resources or entities. The `Uuid.NAMESPACE_URL` is used as an example namespace. ```dart uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com'); // -> "c74a196f-f19d-5ea9-bffd-a2742432fc9c" ``` -------------------------------- ### Generate v4 UUID with positional parameters Source: https://pub.dev/packages/uuid/versions/1 Generates a v4 UUID using a specified RNG and positional parameters. This example utilizes `UuidUtil.mathRNG` and provides a positional argument. It returns the UUID as a string. ```dart import 'package:uuid/uuid_util.dart'; uuid.v4(options: { 'rng': UuidUtil.mathRNG, 'positionalArgs': [1] }); // -> "09a91894-e93f-4141-a3ec-82eb32f2a3ef" ``` -------------------------------- ### Add uuid package dependency (Dart) Source: https://pub.dev/packages/uuid/versions/0.0.6/install This command adds the uuid package as a dependency to your Dart project. It automatically updates your pubspec.yaml file and runs `dart pub get` to fetch the package. Ensure you have Dart SDK installed and configured. ```bash $ dart pub add uuid ``` -------------------------------- ### Dart UUID Generation Example Source: https://pub.dev/packages/uuid/versions/1.0.0/example Demonstrates how to generate different versions of UUIDs using the uuid package in Dart. This includes v1 (time-based), v4 (random), and v5 (namespace-name-based) UUIDs. Ensure the 'uuid' package is added as a dependency. ```dart import 'package:uuid/uuid.dart'; void main() { var uuid = new Uuid(); // Generate a v1 (time-based) id uuid.v1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a' // Generate a v4 (random) id uuid.v4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' // Generate a v5 (namespace-name-sha1-based) id uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com'); // -> 'c74a196f-f19d-5ea9-bffd-a2742432fc9c' } ``` -------------------------------- ### Example pubspec.yaml dependency for uuid Source: https://pub.dev/packages/uuid/versions/2.0.3/install This snippet shows how the uuid package dependency is represented in a Dart project's `pubspec.yaml` file after running `dart pub add uuid`. The `^` symbol indicates compatible versioning. ```yaml dependencies: uuid: ^2.0.3 ``` -------------------------------- ### Add uuid Package Dependency (pubspec.yaml) Source: https://pub.dev/packages/uuid/versions/0.1.1/install Example of how the uuid package dependency is declared in a Dart project's pubspec.yaml file. This entry specifies the package name and its version constraint. ```yaml dependencies: uuid: ^0.1.1 ``` -------------------------------- ### Generate v4 UUID with named parameters Source: https://pub.dev/packages/uuid/versions/1 Generates a v4 UUID using a specified RNG and named parameters. This example uses `UuidUtil.mathRNG` and passes a seed value via `namedArgs`. It returns the UUID as a string. ```dart import 'package:uuid/uuid_util.dart'; uuid.v4(options: { 'rng': UuidUtil.mathRNG, 'namedArgs': new Map.fromIterables([const Symbol('seed')],[1]) }); // -> "09a91894-e93f-4141-a3ec-82eb32f2a3ef" ``` -------------------------------- ### Generate RFC4122 UUIDs (v1, v4, v5) in Dart Source: https://pub.dev/packages/uuid/versions/1 Provides examples of generating different versions of RFC4122 UUIDs using the uuid package. It covers time-based (v1), random (v4), and namespace-name-based (v5) UUID generation. ```dart // Generate a v1 (time-based) id uuid.v1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a' // Generate a v4 (random) id uuid.v4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' // Generate a v5 (namespace-sha1-based) id uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com'); // -> 'c74a196f-f19d-5ea9-bffd-a2742432fc9c' ``` -------------------------------- ### Initialize UUID with Custom CryptoRNG in Dart Source: https://pub.dev/packages/uuid/versions/2 This example shows how to initialize the Uuid class with custom options, specifically by providing a cryptographically secure random number generator (cryptoRNG) as the global RNG. This ensures stronger randomness for generated UUIDs. ```dart var uuid = new Uuid(options: { 'grng': UuidUtil.cryptoRNG }) // Generate a v4 (random) id that will use cryptRNG for its rng function uuid.v4(); ``` -------------------------------- ### Add uuid package to Dart project Source: https://pub.dev/packages/uuid/versions/0.0.7/install This command adds the uuid package as a dependency to your Dart project's pubspec.yaml file. It automatically runs `dart pub get` to fetch the package. ```shell dart pub add uuid ``` -------------------------------- ### Generate two v5 UUIDs in a single buffer Source: https://pub.dev/packages/uuid/versions/1 Generates two v5 UUIDs and writes their byte representations into a single buffer. The `offset` parameter controls the starting position for each UUID within the buffer, enabling efficient storage. ```dart var myBuffer = new List(32); uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com', buffer: myBuffer); uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com', buffer: myBuffer, offset: 16); ``` -------------------------------- ### Generate v4 UUID with different RNG Source: https://pub.dev/packages/uuid/versions/1 Generates a v4 UUID using a specified random number generator (RNG) method. This example demonstrates using `UuidUtil.cryptoRNG` for cryptographic randomness. It returns the UUID as a string. ```dart import 'package:uuid/uuid_util.dart'; uuid.v4(options: { 'rng': UuidUtil.cryptoRNG }); // -> "109156be-c4fb-41ea-b1b4-efe1671c5836" ``` -------------------------------- ### Add uuid to pubspec Dependencies Source: https://pub.dev/packages/uuid/versions/1 This snippet shows how to add the uuid package to your project's pubspec.yaml file. It specifies the dependency with a version constraint, allowing for easy installation via 'pub install'. ```yaml dependencies: uuid: 1.0.0 ``` -------------------------------- ### Generate RFC4122 UUIDs in Dart Source: https://pub.dev/packages/uuid/versions/2.0.0/example Demonstrates how to generate different versions of UUIDs using the uuid package. It shows examples for v1 (time-based), v4 (random), v4 with crypto-randomness, and v5 (namespace-name-based) UUIDs. Requires the 'uuid' package. ```dart import 'package:uuid/uuid.dart'; import 'package:uuid/uuid_util.dart'; void main() { var uuid = new Uuid(); // Generate a v1 (time-based) id uuid.v1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a' // Generate a v4 (random) id uuid.v4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' // Generate a v4 (crypto-random) id uuid.v4(options: {'rng': UuidUtil.cryptoRNG}); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' // Generate a v5 (namespace-name-sha1-based) id uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com'); // -> 'c74a196f-f19d-5ea9-bffd-a2742432fc9c' } ``` -------------------------------- ### Generate RFC4122 UUIDs (v1, v4, v5) in Dart Source: https://pub.dev/packages/uuid/versions/2.2.0/example This snippet demonstrates how to generate different versions of UUIDs using the uuid package. It shows examples for v1 (time-based), v4 (random), and v5 (namespace-name-based) UUIDs, including options for custom generation parameters. ```dart import 'package:uuid/uuid.dart'; import 'package:uuid/uuid_util.dart'; void main() { var uuid = Uuid(); // Generate a v1 (time-based) id var v1 = uuid.v1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a' var v1_exact = uuid.v1(options: { 'node': [0x01, 0x23, 0x45, 0x67, 0x89, 0xab], 'clockSeq': 0x1234, 'mSecs': DateTime.utc(2011,11,01).millisecondsSinceEpoch, 'nSecs': 5678 }); // -> '710b962e-041c-11e1-9234-0123456789ab' // Generate a v4 (random) id var v4 = uuid.v4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' // Generate a v4 (crypto-random) id var v4_crypto = uuid.v4(options: {'rng': UuidUtil.cryptoRNG}); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' // Generate a v5 (namespace-name-sha1-based) id var v5 = uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com'); // -> 'c74a196f-f19d-5ea9-bffd-a2742432fc9c' print(v1); print(v1_exact); print(v4); print(v4_crypto); print(v5); } ``` -------------------------------- ### Generate two v4 UUIDs in a single buffer Source: https://pub.dev/packages/uuid/versions/1 Efficiently generates two v4 UUIDs by writing their byte representations directly into a provided buffer. The `offset` parameter allows specifying the starting position for each UUID within the buffer. ```dart var myBuffer = new List(32); uuid.v4(buffer: myBuffer); uuid.v4(buffer: myBuffer, offset: 16); ``` -------------------------------- ### Generate Different UUID Versions in Dart Source: https://pub.dev/packages/uuid/versions/4.0.0-beta1/example Demonstrates how to generate various RFC4122 compliant UUIDs (v1, v4, v5, v6, v7, v8) using the uuid package. It shows both default generation and generation with specific options for each version. This example requires the 'uuid' and 'uuid_util' packages. ```dart import 'package:uuid/uuid.dart'; import 'package:uuid/uuid_util.dart'; void main() { var uuid = Uuid(); // Generate a v1 (time-based) id var v1 = uuid.v1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a' var v1_exact = uuid.v1(options: { 'node': [0x01, 0x23, 0x45, 0x67, 0x89, 0xab], 'clockSeq': 0x1234, 'mSecs': DateTime.utc(2011, 11, 01).millisecondsSinceEpoch, 'nSecs': 5678 }); // -> '710b962e-041c-11e1-9234-0123456789ab' // Generate a v4 (random) id var v4 = uuid.v4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' // Generate a v4 (crypto-random) id var v4_crypto = uuid.v4(options: {'rng': UuidUtil.cryptoRNG}); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' // Generate a v5 (namespace-name-sha1-based) id var v5 = uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com'); // -> 'c74a196f-f19d-5ea9-bffd-a2742432fc9c' // Generate a v6 (time-based) id var v6 = uuid.v6(); // -> '1ebbc608-7459-6a20-bc85-0d10b6a52acd' var v6_exact = uuid.v6(options: { 'node': [0x01, 0x23, 0x45, 0x67, 0x89, 0xab], 'clockSeq': 0x1234, 'mSecs': DateTime.utc(2011, 11, 01).millisecondsSinceEpoch, 'nSecs': 5678, }); // -> '1e1041c7-10b9-662e-9234-0123456789ab' // Generate a v7 (time-based) id var v7 = uuid.v7(); // -> 060ab53c-0bb2-7482-8000-ab029e8fa2ea var v7_exact = uuid.v7(options: { 'randomBytes': [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0x01, 0x23, 0x45, 0x67], 'time': DateTime.utc(2011, 10, 9, 8, 7, 6, 543, 210).millisecondsSinceEpoch, }); // -> '04e91562-0884-7fea-9234-0123456789ab' // Generate a v8 (time-random) id var v8 = uuid.v8(); // -> '1e1041c7-10b9-662e-9234-0123456789ab' var v8_exact = uuid.v8(options: { 'randomBytes': [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0x01, 0x23, 0x45, 0x67], 'time': DateTime.utc(2011, 10, 9, 8, 7, 6, 543, 210), }); // -> '1e1041c7-10b9-662e-9234-0123456789ab' print('v1 | ' + v1); print('v1 exact | ' + v1_exact); print('v4 | ' + v4); print('v4 crypto | ' + v4_crypto); print('v5 | ' + v5); print('v6 | ' + v6); print('v6 exact | ' + v6_exact); print('v7 | ' + v7); print('v7 exact | ' + v7_exact); print('v8 | ' + v8); print('v8 exact | ' + v8_exact); } ``` -------------------------------- ### Generate RFC4122 UUIDs in Dart Source: https://pub.dev/packages/uuid/index These examples illustrate how to generate different versions of RFC4122 compliant UUIDs using the initialized Uuid instance. It covers time-based (v1), random (v4), and namespace-name-based (v5) UUID generation. ```dart // Generate a v1 (time-based) id uuid.v1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a' // Generate a v4 (random) id uuid.v4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' // Generate a v5 (namespace-name-sha1-based) id uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com'); // -> 'c74a196f-f19d-5ea9-bffd-a2742432fc9c' ``` -------------------------------- ### UUID v3.0.4: Improved Microsoft GUID Validation Source: https://pub.dev/packages/uuid/versions/4.1.0/changelog Version 3.0.4 enhances the `isValidUUID` function to better handle Microsoft GUIDs that deviate only in the Variant setting. It also improves error output for better developer feedback and refines general validation logic for multiple cases. ```dart import 'package:uuid/uuid.dart'; // Example usage of isValidUUID final microsoftGuid = '00000000-0000-0000-0000-000000000000'; // Example, actual GUID might differ final isValid = Uuid().isValidUUID(microsoftGuid); // Or Uuid.isValidUUID(microsoftGuid) ``` -------------------------------- ### Add uuid package dependency to Dart or Flutter project Source: https://pub.dev/packages/uuid/install This command adds the uuid package as a dependency to your Dart or Flutter project's pubspec.yaml file, ensuring the package is available for use. It automatically handles running `dart pub get` or `flutter pub get`. ```bash $ dart pub add uuid ``` ```bash $ flutter pub add uuid ``` -------------------------------- ### Generate Multiple Binary UUIDs in a Buffer in Dart Source: https://pub.dev/packages/uuid/versions/1 Shows how to generate multiple UUIDs directly into a byte buffer with specified offsets. This is useful for performance-critical applications where generating binary UUIDs and processing them in bulk is required. It also demonstrates how to unparse the buffer to get string representations. ```dart // Generate two ids in an array var myBuffer = new List(32); // -> [] uuid.v1(buffer: myBuffer); // -> [115, 189, 5, 128, 201, 91, 17, 225, 146, 52, 109, 0, 9, 0, 52, 128, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null] uuid.v1(buffer: myBuffer, offset: 16); // -> [115, 189, 5, 128, 201, 91, 17, 225, 146, 52, 109, 0, 9, 0, 52, 128, 115, 189, 5, 129, 201, 91, 17, 225, 146, 52, 109, 0, 9, 0, 52, 128] // Optionally use uuid.unparse() to get stringify the ids uuid.unparse(buffer: myBuffer); // -> '73bd0580-c95b-11e1-9234-6d0009003480' uuid.unparse(buffer: myBuffer, offset: 16) // -> '73bd0581-c95b-11e1-9234-6d0009003480' ``` -------------------------------- ### Configure Uuid Constructor with Custom RNG in Dart Source: https://pub.dev/packages/uuid/versions/3.0 This Dart example shows how to instantiate the Uuid generator with custom random number generator options. It specifically demonstrates using UuidUtil.cryptoRNG globally for generating v4 UUIDs, ensuring cryptographically strong randomness. ```dart var uuid = Uuid(options: { 'grng': UuidUtil.cryptoRNG }); // Generate a v4 (random) id that will use cryptRNG for its rng function uuid.v4(); ``` -------------------------------- ### Constant Uuid Constructor and Code Adjustments (Dart) Source: https://pub.dev/packages/uuid/versions/4.0.0/changelog This example shows how the `Uuid` constructor has been made constant, allowing for `const` declarations. This optimization improves performance by enabling compile-time creation of `Uuid` instances and ensures that all related code has been adjusted accordingly. ```dart import 'package:uuid/uuid.dart'; // Using the constant constructor const uuid = Uuid(); final uuidV4 = uuid.v4(); // Use the const instance print(uuidV4); // Example of how internal code might be adjusted for const constructors // (Illustrative - actual implementation details may vary) class Uuid { // ... other properties const Uuid(); // Made constant String v4() { // ... implementation using const instance properties if any return 'generated-v4-uuid'; // Placeholder } } ``` -------------------------------- ### UuidValue Constructors and Operators (Dart) Source: https://pub.dev/packages/uuid/versions/4.0.0/changelog This example showcases new experimental constructors `fromByteList` and `fromList` for `UuidValue`, along with the overridden `==` operator and `hashCode`. These additions provide more ways to create and compare `UuidValue` objects, improving usability and integration with collection types. ```dart import 'package:uuid/uuid.dart'; // Using fromByteList final byteList = Uint8List.fromList([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]); final uuidFromBytes = UuidValue.fromByteList(byteList); // Using fromList final list = List.generate(16, (i) => i); final uuidFromList = UuidValue.fromList(list); // Using == operator final uuid1 = UuidValue.parse('123e4567-e89b-12d3-a456-426614174000'); final uuid2 = UuidValue.parse('123e4567-e89b-12d3-a456-426614174000'); print(uuid1 == uuid2); // true // Using hashCode print(uuid1.hashCode == uuid2.hashCode); // true ``` -------------------------------- ### Replacing UuidUtil RNG Functions with RNG Classes (Dart) Source: https://pub.dev/packages/uuid/versions/4.0.0/changelog This code example illustrates the transition from using `UuidUtil.mathRNG()` and `UuidUtil.cryptoRNG()` to the new `MathRNG().generate()` and `CryptoRNG().generate()` classes, respectively. It also shows how custom crypto implementations should now implement the `RNG` abstract class. This change aims to improve the structure and usability of RNG in the uuid package. ```dart import 'package:uuid/uuid.dart'; // Old way (deprecated) // final uuid = Uuid(options: GlobalOptions()..rng = UuidUtil.mathRNG()); // New way final uuid = Uuid(options: GlobalOptions()..rng = MathRNG()); // For custom crypto implementations abstract class CustomCryptoRNG implements RNG { @override Uint8List generate(); } // Usage of custom crypto RNG class MyCryptoRNG implements CustomCryptoRNG { @override Uint8List generate() { // Your custom crypto logic here return Uint8List(16); } } final uuidWithCustomCrypto = Uuid(options: GlobalOptions()..rng = MyCryptoRNG()); ``` -------------------------------- ### isValidUuid Function Signature Change (Dart) Source: https://pub.dev/packages/uuid/versions/4.0.0/changelog This example shows the updated signature of the `isValidUuid` function. It now accepts two optional parameters, `fromString` and `fromList`, allowing for more flexible validation of UUIDs from different source types. This improves the robustness and user-friendliness of the validation process. ```dart import 'package:uuid/uuid.dart'; final uuidString = '123e4567-e89b-12d3-a456-426614174000'; final byteList = Uint8List.fromList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); // Validate from string print(isValidUuid(uuidString)); // true // Validate from byte list print(isValidUuid.fromList(byteList)); // true // Validate from string with specific flag (if needed, though fromString is default) print(isValidUuid(uuidString, fromString: true)); // true ``` -------------------------------- ### Null-Safe UUID Parsing with FormatException (Dart) Source: https://pub.dev/packages/uuid/versions/4.0.0/changelog This example shows the behavior change in the `parse()` function after the introduction of null safety. Instead of returning NIL or partially handled UUIDs, `parse()` now throws a `FormatException` for invalid inputs. This enforces stricter data handling and clearer error reporting. ```dart import 'package:uuid/uuid.dart'; final invalidUuidString = 'invalid-uuid-string'; try { final uuidValue = parse(invalidUuidString); } catch (e) { if (e is FormatException) { print('Caught expected FormatException: ${e.message}'); } else { print('Caught unexpected error: $e'); } } ``` -------------------------------- ### Run uuid Package Tests with Dart VM Source: https://pub.dev/packages/uuid/versions/0 Instructions for running the tests for the uuid Dart package using the Dart VM. This command executes the test suite located in the `test/uuid_test.dart` file. ```bash dart test\uuid_test.dart ``` -------------------------------- ### Add uuid Dependency to pubspec Source: https://pub.dev/packages/uuid/index This snippet shows how to add the uuid package as a dependency in your Dart project's pubspec file. After adding the dependency, you would typically run 'pub install' or 'flutter pub get' to download and integrate the package. ```yaml dependencies: uuid: ^4.4.2 ``` -------------------------------- ### Uuid Constructor and Options Source: https://pub.dev/packages/uuid/versions/3 Details on how to instantiate the Uuid class and configure global random number generators. ```APIDOC ## Uuid Constructor and Options ### Description Configures the global random number generator (RNG) settings for UUID generation. ### Method * **`Uuid({Map options: null})`** * **Description**: Constructor for the Uuid class. Allows setting global RNG options. * **Parameters**: * `options` (Map) - Optional map for configuring RNG settings. * `grng` (Function) - Global Random Number Generator function. Should return a list of 16 byte values. * `gNamedArgs` (Map) - Named arguments for the global RNG function. * `gPositionalArgs` (List) - Positional arguments for the global RNG function. * `v1rng` (Function) - Random Number Generator function for v1 UUID seed. Should return a list of 16 byte values. * `v1rngNamedArgs` (Map) - Named arguments for the v1 RNG function. * `v1rngPositionalArgs` (List) - Positional arguments for the v1 RNG function. * **Default RNG**: `Uuid.mathRNG` ### Request Example (Using CryptoRNG globally) ```dart import 'package:uuid/uuid.dart'; var uuid = Uuid(options: { 'grng': UuidUtil.cryptoRNG }); // Generate a v4 (random) id that will use cryptoRNG for its random number generation String secureV4Id = uuid.v4(); ``` ### Response Example (Success) ```json { "message": "UUID generated successfully with configured RNG.", "generatedId": "[generated_uuid]" } ``` ``` -------------------------------- ### Run UUID package tests (Dart) Source: https://pub.dev/packages/uuid/versions/3.0 Demonstrates how to run the tests for the uuid package in different Dart environments. For dartvm, a specific test file is executed. For Browser/Flutter, direct testing is not explicitly shown, but the package is known to be used in these environments. ```dart # In dartvm dart test\uuid_test.dart # In Browser/flutter # No in browser testing, but I know many use it in Web and Flutter projects. ``` -------------------------------- ### Run UUID tests in Dart VM Source: https://pub.dev/packages/uuid/versions/1 Provides the command to execute the UUID package's test suite within the Dart Virtual Machine (VM) environment. This is essential for verifying the package's functionality and integrity. ```bash dart test\uuid_test.dart ``` -------------------------------- ### UUID Generation API Source: https://pub.dev/packages/uuid/versions/0 This section details the methods available for generating different versions of UUIDs using the uuid package. ```APIDOC ## uuid.v1 ### Description Generates and returns an RFC4122 v1 (timestamp-based) UUID. ### Method `uuid.v1({Map options: null, List buffer: null, int offset: 0})` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **options** (Map) - Optional: Allows specifying node, clock sequence, milliseconds, and nanoseconds for the UUID. If not provided, defaults are used. - **node** (List) - Node ID as a List of 6 bytes. - **clockseq** (Number) - Clock sequence between 0 and 0x3fff. - **msecs** (Number) - Time in milliseconds since Unix Epoch. - **nsecs** (Number) - Additional time in 100-nanosecond units (0-9999). - **buffer** (List) - Optional: An array or buffer to write the UUID bytes into. - **offset** (Int) - Optional: The starting index in the `buffer` for writing the UUID. ### Request Example ```dart uuid.v1(options: { 'node': [0x01, 0x23, 0x45, 0x67, 0x89, 0xab], 'clockSeq': 0x1234, 'mSecs': new DateTime(2011,11,01).millisecondsSinceEpoch, 'nSecs': 5678 }) ``` ### Response Returns the string representation of the UUID, or the `buffer` if specified. #### Success Response (200) - **uuid_string** (String) - The generated v1 UUID. #### Response Example ``` "1d6a6e2e-0457-11e1-9234-0123456789ab" ``` ## uuid.v4 ### Description Generates and returns an RFC4122 v4 (random) UUID. ### Method `uuid.v4()` ### Parameters None ### Request Example ```dart uuid.v4() ``` ### Response Returns the string representation of the v4 UUID. #### Success Response (200) - **uuid_string** (String) - The generated v4 UUID. #### Response Example ``` "110ec58a-a0f2-4ac4-8393-c866d813b8d1" ``` ## uuid.v5 ### Description Generates and returns an RFC4122 v5 (namespace-name-SHA1-based) UUID. ### Method `uuid.v5(String namespace, String name)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **namespace** (String) - The namespace UUID. Use predefined constants like `Uuid.NAMESPACE_URL`. - **name** (String) - The name to generate the UUID from. ### Request Example ```dart uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com') ``` ### Response Returns the string representation of the v5 UUID. #### Success Response (200) - **uuid_string** (String) - The generated v5 UUID. #### Response Example ``` "c74a196f-f19d-5ea9-bffd-a2742432fc9c" ``` ``` -------------------------------- ### Configure pubspec.yaml for uuid Package Source: https://pub.dev/packages/uuid/versions/0.2.0/install This snippet shows how the uuid package dependency is declared in the pubspec.yaml file. This configuration ensures the package is available for your project. ```yaml dependencies: uuid: ^0.2.0 ``` -------------------------------- ### Add uuid Dependency to pubspec.yaml Source: https://pub.dev/packages/uuid/versions/3.0 This snippet shows how to add the 'uuid' package as a dependency in your Dart project's pubspec.yaml file. Ensure you have the correct version specified. After updating, run 'pub install'. ```yaml dependencies: uuid: 3.0.0-nullsafety.1 ``` -------------------------------- ### Generate UUIDs (v1, v4, v5, v6, v7, v8) in Dart Source: https://pub.dev/packages/uuid/versions/4.5.0/example This Dart code snippet demonstrates how to generate different versions of UUIDs using the 'uuid' package. It shows basic generation as well as generation with specific configurations for each version. Dependencies include 'uuid', 'crypto', and 'dart:math'. ```dart import 'package:uuid/data.dart'; import 'package:uuid/uuid.dart'; import 'package:uuid/rng.dart'; void main() { var uuid = Uuid(); // Generate a v1 (time-based) id var v1 = uuid.v1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a' var v1Exact = uuid.v1( config: V1Options( 0x1234, DateTime.utc(2011, 11, 01).millisecondsSinceEpoch, 5678, [0x01, 0x23, 0x45, 0x67, 0x89, 0xab], null)); // -> '710b962e-041c-11e1-9234-0123456789ab' // Generate a v4 (random) id var v4 = uuid.v4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' // Generate a v4 (crypto-random) id var v4Crypto = uuid.v4(config: V4Options(null, CryptoRNG())); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' // Generate a v5 (namespace-name-sha1-based) id var v5 = uuid.v5(Namespace.url.value, 'www.google.com'); // -> 'c74a196f-f19d-5ea9-bffd-a2742432fc9c' // Generate a v6 (time-based) id var v6 = uuid.v6(); // -> '1ebbc608-7459-6a20-bc85-0d10b6a52acd' var v6Exact = uuid.v6( config: V6Options( 0x1234, DateTime.utc(2011, 11, 01).millisecondsSinceEpoch, 5678, [0x01, 0x23, 0x45, 0x67, 0x89, 0xab], null)); // -> '1e1041c7-10b9-662e-9234-0123456789ab' // Generate a v7 (time-based) id var v7 = uuid.v7(); // -> 060ab53c-0bb2-7482-8000-ab029e8fa2ea var v7Exact = uuid.v7( config: V7Options( DateTime.utc(2011, 10, 9, 8, 7, 6, 543, 210).millisecondsSinceEpoch, [ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0x01, 0x23, 0x45, 0x67 ])); // -> '04e91562-0884-7fea-9234-0123456789ab' // Generate a v8 (time-random) id var v8 = uuid.v8(); // -> '1e1041c7-10b9-662e-9234-0123456789ab' var v8Exact = uuid.v8( config: V8Options(DateTime.utc(2011, 10, 9, 8, 7, 6, 543, 210), [ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0x01, 0x23, 0x45, 0x67 ])); // -> '1e1041c7-10b9-662e-9234-0123456789ab' print('v1 | $v1'); print('v1 exact | $v1Exact'); print('v4 | $v4'); print('v4 crypto | $v4Crypto'); print('v5 | $v5'); print('v6 | $v6'); print('v6 exact | $v6Exact'); print('v7 | $v7'); print('v7 exact | $v7Exact'); print('v8 | $v8'); print('v8 exact | $v8Exact'); } ``` -------------------------------- ### Generate RFC4122 UUIDs in Dart Source: https://pub.dev/packages/uuid/versions/2.0.0-rc1/example Demonstrates how to generate different versions of UUIDs using the uuid Dart package. It covers v1 (time-based), v4 (random and crypto-random), and v5 (namespace-name-based) UUID generation. Requires importing 'package:uuid/uuid.dart' and potentially 'package:uuid/uuid_util.dart'. ```dart import 'package:uuid/uuid.dart'; import 'package:uuid/uuid_util.dart'; void main() { var uuid = new Uuid(); // Generate a v1 (time-based) id uuid.v1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a' // Generate a v4 (random) id //uuid.v4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' // Generate a v4 (crypto-random) id //uuid.v4(options: {'rng': UuidUtil.cryptoRNG}); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' // Generate a v5 (namespace-name-sha1-based) id uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com'); // -> 'c74a196f-f19d-5ea9-bffd-a2742432fc9c' } ``` -------------------------------- ### Generate v1 UUID with Custom Options in Dart Source: https://pub.dev/packages/uuid/versions/1 Illustrates how to generate a v1 (timestamp-based) UUID with fully specified options, including node, clock sequence, milliseconds, and nanoseconds. This allows for precise control over the generated UUID's components. ```dart uuid.v1(options: { 'node': [0x01, 0x23, 0x45, 0x67, 0x89, 0xab], 'clockSeq': 0x1234, 'mSecs': new DateTime(2011, DateTime.DECEMBER, 1).millisecondsSinceEpoch, 'nSecs': 5678 }) // -> "1d6a6e2e-0457-11e1-9234-0123456789ab" ``` -------------------------------- ### UUID v4.0.0-beta2: Uuid Constructor with GlobalOptions Source: https://pub.dev/packages/uuid/versions/4.1.0/changelog The `Uuid` class constructor in v4.0.0-beta2 now accepts a `GlobalOptions` class instead of a `Map`. This change aims to replace the Map parameter and improve constructor Reworked. Options are now taken in by the new options classes. Versions v6, v7, v8 now only take the new options class. State has been moved out of classes. Const is now supported properly again. Tests use `const Uuid` to catch regressions. The `options` parameter in v1, v4, and v5 constructors is deprecated. ```dart import 'package:uuid/uuid.dart'; // Old usage (pre v4.0.0-beta2): // final uuid = Uuid(options: {'some': 'option'}); // New usage: final uuid = Uuid(options: GlobalOptions()); // Assuming GlobalOptions is the default or can be instantiated directly // For specific versions that now require the options class: // final uuidV6 = Uuid(version: 6, options: GlobalOptions()); ```