license method Null safety

Future<LicenseRecord> license(
  1. String ptr,
  2. List<LicenseUse> uses,
  3. String terms,
  4. {String? origin,
  5. List<TitleTag> tags = const [],
  6. String? titleDescription,
  7. String? licenseDescription,
  8. DateTime? expiry}
)

Create a new LicenseRecord.

If a TitleRecord for the ptr and origin is not found. A new TitleRecord is created. If a TitleRecord is found, tags and titleDescription parameters are ignored.

Parameters:

ptr - The Pointer Records identifies data stored in your system, similar to a foreign key. Learn more about selecting good pointer records.

uses - A List defining how and where an asset may be used, in a the format of usecases and destinations, per the terms of the license. Learn more about defining uses.

terms - The legal terms of the contract (a lot of words).

origin - An optional override of the default origin specified in init. Follow a reverse-DNS syntax. i.e. com.myco.myapp.

tags - A List of metadata tags included in the TitleRecord describing the asset, for your use in record search and filtering. Learn more about adding tags. Only set IF a title does not already exist for the ptr.

titleDescription - Sets the TitleRecord description IF a title does not already exist for the ptr. A short, human-readable, description of the TitleRecord as a future reminder.

licenseDescription - A short, human-readable, description of the LicenseRecord as a future reminder.

expiry - A LicenseRecord expiration date. Leave null if the license never expires.

Returns the created LicenseRecord

Implementation

Future<LicenseRecord> license(String ptr, List<LicenseUse> uses, String terms,
    {String? origin,
    List<TitleTag> tags = const [],
    String? titleDescription,
    String? licenseDescription,
    DateTime? expiry}) async {
  ptr = _hashPtr(ptr);
  TitleModel? title = _titleService.getByPtr(ptr, origin: origin);
  title ??= await _titleService.create(ptr,
      origin: origin, tags: tags, description: titleDescription);
  LicenseModel license = await _licenseService.create(
      title.transactionId!, uses, terms,
      description: licenseDescription, expiry: expiry);
  return _toLicense(title, license);
}