搜尋套件、儲存庫與 APP 分類

套件詳情v0.3.1

flutter_guid

模擬 C# Guid。產生新的 UUID,向類別中新增 Guid 類型的變數。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
3230
喜歡數
20
Pub 分數
135

安裝套件

flutter pub add flutter_guid

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

flutter_guid 是一個 Dart 套件,模擬 C# Guid 功能,讓開發者能在 Flutter 應用中產生和管理 UUID(通用唯一識別碼)。它提供了一個 Guid 類來建立新的唯一識別碼,並允許將 Guid 類型的變數加入自訂類別中。該套件支援所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,非常適合需要一致識別碼產生的跨平台應用。在資料同步、會話追蹤或資料庫金鑰管理等情境中特別實用,這些情境對唯一性和可靠性至關重要。

適用情境

  • 為資料庫記錄生成唯一ID
  • 跨裝置追蹤使用者會話
  • 在客戶端之間同步資料
  • 建立安全令牌
  • 在狀態管理中管理實體識別碼

主要特色

  • 跨平台 UUID 產生
  • C# Guid 相似之 API 設計
  • 自定義類別中對 Guid 類型的支援
  • 不可變且可序列化的 Guid 物件
  • 透過 pub.dev 輕鬆整合

適合對象

  • 需要全域唯一識別碼的應用程式
  • 後端整合的Flutter應用
  • 具有同步需求的資料密集型應用程式
  • 熟悉 C# Guid 模式的開發人員
  • 跨平台需要一致 ID 生成的項目

使用建議

  • 需要了解UUID標準
  • 不適合用於加密金鑰產生
  • 可能會為簡單使用案例增加少量開銷
  • 僅限識別碼生成,不包含加密或雜湊

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

flutter_guid

A flutter package that emulates the C# type Guid. Use this package to:

  1. Generate new UUIDs.
  2. Add variables of type Guid to your classes.
  3. Compare two 'Guid' variables safely against each other.
  4. Guarantee validity of data when working with UUID values.

Getting Started

Installing

Install from https://pub.dev/packages/flutter_guid#-installing-tab- , "flutter_guid's installation page on pub.dev"

Usage
Add to your class.
import 'package:flutter_guid/flutter_guid.dart';

class Employee{
  final Guid id;
  final Guid departmentId;

  Employee({this.id, this.departmentId});
}
Initialize Guid values

// initialize a guid from a string
final accountsDepartmentId = new Guid("41e879aa-859c-4bda-b77b-37b7e07c6674");

 // Generate a guid on the fly (Uses the superb package 'https://pub.dev/packages/uuid').
final employeeId = Guid.newGuid;

Compare Guids
// initialize a guid from a lowercase string
final accountsDepartmentIdLowerCase = new Guid("41e879aa-859c-4bda-b77b-37b7e07c6674");

// initialize a guid with same string, but UPPERCASE
final accountsDepartmentIdUpperCase = new Guid("41E879AA-859C-4BDA-B77B-37B7E07C6674");

// performs case-insensitive comparison and evaluates to 'true'
final equal = accountsDepartmentIdUpperCase == accountsDepartmentIdLowerCase;

Getting the UUID value contained in the GUID
final Guid accountsDepartmentIdLowerCase = new Guid("41e879aa-859c-4bda-b77b-37b7e07c6674");

// this works.
String uuidString = accountsDepartmentIdLowerCase.value;

// this also works.
uuidString = accountsDepartmentIdLowerCase.toString();

Testing

Basic Testing

Clone the repo and run flutter test

Testing With Coverage Information (Linux only)
  1. Ensure you have lcov installed and setup on your system (http://ltp.sourceforge.net/coverage/lcov.php).
  2. Ensure the run-tests script in the project root is executable (chmod +x ./run-tests.sh).
  3. Execute the run-tests script in the project root ./run-tests.sh.
  4. Navigate into directory ./coverage/html/ (relative to project root).
  5. Open index.html to view coverage information.
Coverage Information On Other Systems

It is unlikely that I'll be porting the run-tests.sh script to other systems, my reason mostly being that I don't frequently use any other OS and would not want to pick a sub-optimal tool for coverage generation (also laziness probably is a factor).

Anyhow, it should be fairly straight-forward to do the porting if you so wish.

The run-tests.sh consists of all of two lines:

  1. flutter test --coverage
  2. genhtml ./coverage/lcov.info -o ./coverage/html

The first line is platform independent and generates the file ./coverage/lcov.info (again relative to project root). On Linux, we can consume the coverage info contained in this file via the lcov tool. On Windows and other platforms, there exists also tools that would be able to similarly consume the coverage information and produce human friendly output.

In essense, port the script to desired platform by

  1. Keeping the first line 'as is'.
  2. Finding a tool to process the ./coverage/lcov.info file.
  3. Profit!

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。