canonicalKey property

String get canonicalKey

Get the canonical key for the context.

An invalid context cannot be used to generate a key, so an empty string will be returned.

Implementation

String get canonicalKey {
  if (!valid) {
    return '';
  }
  if (_canonicalKeyMemo != null) {
    return _canonicalKeyMemo!;
  }

  if (attributesByKind.length == 1 && attributesByKind.containsKey('user')) {
    return attributesByKind['user']!.key;
  }

  final kinds = attributesByKind.keys.toList(growable: false);
  kinds.sort();
  _canonicalKeyMemo = kinds
      .map((kind) => '$kind:${_encodeKey(attributesByKind[kind]!.key)}')
      .join(':');

  return _canonicalKeyMemo!;
}