搜索插件、代码仓与 APP 分类

GitHub 代码仓rocket-libs/flutter_guid

flutter_guid

一个模拟 C# 类型 Guid 的 Flutter 包。使用此包生成新的 UUID,将类型为 Guid 的变量添加到您的类中,并安全地比较两个 'Guid' 变量。

flutter_guid 项目封面
星标
3
复刻
10
最近推送(UTC)
2024年5月24日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

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!
rocket-libs GitHub avatar
GitHub 作者

rocket-libs ↗

语言DartShell

此仓库发布的插件

使用的依赖

依赖清单 4 项

  • flutter{"sdk":"flutter"}
  • uuid^3.0.7
  • validators^3.0.0
  • flutter_test开发依赖{"sdk":"flutter"}

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗