flutter_guid 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 85

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!

[0.0.1] - Initial Release. #

  • Describe initial release.

[0.1.0] - Documentation and Testing #

  • Added tests and information in Readme.md

example/example.dart

import 'package:flutter_guid/flutter_guid.dart';

import 'Employee.dart';

class EmployeeManager{
  static final String workShopGuidString = "edea6638-dd1d-4e26-a207-e4044ad22687";
  final employeeList = new List<Employee>();
  
   // initialize a guid from a string
  final accountsDepartmentId = new Guid("41e879aa-859c-4bda-b77b-37b7e07c6674");
  
  // initialize a new guid with the 'workShopGuidString' value, Lowercased.
  final workshopDepartmentIdLowerCased = new Guid(workShopGuidString.toLowerCase());

  // initialize a second guid with the 'workShopGuidString' value, BUT UPPERCASED this time.
  final workshopDepartmentIdUpperCased = new Guid(workShopGuidString.toUpperCase()); 

  populateEmployeeList(){
    final accountant = new Employee(
      departmentId: accountsDepartmentId, // use pre-initialized guid value.
      id: Guid.newGuid // Generate a guid on the fly (Uses the superb package 'https://pub.dev/packages/uuid').
    );

    final engineer = new Employee(
      departmentId: workshopDepartmentIdLowerCased,
      id: Guid.newGuid
    );

    employeeList
      ..add(accountant)
      ..add(engineer);
  }

  Employee getEngineer(){
    
    final theEngineer = employeeList.singleWhere((employee){
      //Comparison done on guid value is case-insensitive
      //employee.departmentId was initialized with a lowercase string but is compared to a guid initialized with an uppercase string and WILL SUCCESSFULLY match
      return employee.departmentId == workshopDepartmentIdUpperCased; 
    });

    return theEngineer;
  }

  bool engineerIdIsDefault(){
    final engineer = getEngineer();

    // Returns true if engineerId == "00000000-0000-0000-0000-000000000000".
    // This value is assigned to Guids if no other value is explicitly set on them
    // NOTE: The guid variable itself if nullable but, its value once initialized is guaranteed to always be either the defaultValue or a valid UUID 
    return engineer.id == Guid.defaultValue;
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_guid: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_guid/flutter_guid.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
70
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
85
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • flutter_guid that is a package requiring null.

Health suggestions

Format lib/FlutterGuidError.dart.

Run flutter format to format lib/FlutterGuidError.dart.

Format lib/flutter_guid.dart.

Run flutter format to format lib/flutter_guid.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
uuid ^2.0.4 2.2.0
validators ^2.0.0+1 2.0.1
Transitive dependencies
asn1lib 0.6.5
basic_utils 2.5.5
charcode 1.1.3
collection 1.14.12 1.14.13
convert 2.1.1
crypto 2.1.5
http 0.12.1
http_parser 3.1.4
intl 0.16.1
json_annotation 3.0.1
logging 0.11.4
meta 1.1.8 1.2.2
path 1.7.0
pedantic 1.9.0 1.9.2
pointycastle 1.0.2
random_string 2.1.0
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
vin_decoder 0.1.2
Dev dependencies
flutter_test