Skip to main content

uid 0.2.0 copy "uid: ^0.2.0" to clipboard
uid: ^0.2.0 copied to clipboard

Generate a unique ID from datetime combined with a random string at a random position, and generate random barcode numbers (5 to 13 characters) using numbers or capital letters.

Unique ID Generator #

A lightweight Dart package for generating unique IDs by inserting random strings into timestamps at random positions, and for generating random barcode numbers. Features

🆔 Generate unique IDs based on current timestamp

🔤 Support for different character sets (mixed case, uppercase only, numbers only)

🏷️ Generate barcode numbers from 5 to 13 characters (numbers only, capital letters only, or both)

⚡ Fast and efficient ID generation

🔢 Batch ID and barcode generation support

Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  uid: ^0.2.0

Import the package:

import 'package:uid/uid.dart';

Usage #

Basic Usage

import 'package:uid/uid.dart';

void main() {
  // Generate a basic unique ID
  String id = UId.getId();
  print(id); // Example: 4824aF254606141
}

Advanced Usage

import 'package:uid/uid.dart';

void main() {
  // Generate ID with custom random string length
  String id1 = UId.getId(quantityOfRandomString: 4);
  print(id1); // Example: 4824aBc3254606141

  // Generate ID with only uppercase letters and numbers
  String id2 = UId.getId(isCapital: true);
  print(id2); // Example: 4824AF254606141

  // Generate ID with only numbers
  String id3 = UId.getId(onlyNumbers: true);
  print(id3); // Example: 482434254606141

  // Combine parameters
  String id4 = UId.getId(
    quantityOfRandomString: 3,
    isCapital: true,
  );
  print(id4); // Example: 4824A2F254606141

  // Generate multiple IDs at once
  List<String> ids = UId.getMultipleIds(
    count: 5,
    quantityOfRandomString: 3,
    onlyNumbers: true,
  );
  print(ids); // Example: [482412354606141, 482435654606142, ...]
}

Barcode Usage

length must be between 5 and 13 (default 13). charset can be:

Charset Characters Example
BarcodeCharset.numeric (default) 0-9 4820193746512
BarcodeCharset.alphabet A-Z QXRMBTZAKDLEW
BarcodeCharset.alphanumeric A-Z and 0-9 7K2QX9M4TB1ZP
import 'package:uid/uid.dart';

void main() {
  // Generate a 13-digit numeric barcode
  String barcode1 = UId.getBarcode();
  print(barcode1); // Example: 4820193746512

  // Generate an 8-character barcode with only capital letters
  String barcode2 = UId.getBarcode(length: 8, charset: BarcodeCharset.alphabet);
  print(barcode2); // Example: QXRMBTZA

  // Generate a 10-character barcode with capital letters and numbers
  String barcode3 = UId.getBarcode(length: 10, charset: BarcodeCharset.alphanumeric);
  print(barcode3); // Example: 7K2QX9M4TB

  // Generate multiple barcodes at once (no duplicates within the list)
  List<String> barcodes = UId.getMultipleBarcodes(count: 5, length: 6);
  print(barcodes); // Example: [583920, 104857, 772031, ...]
}

11
likes
160
points
887
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Generate a unique ID from datetime combined with a random string at a random position, and generate random barcode numbers (5 to 13 characters) using numbers or capital letters.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on uid