搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目

暂无相关数据。