toString method
A string representation of this object.
Some classes have a default textual representation,
often paired with a static parse
function (like int.parse).
These classes will provide the textual representation as
their string representation.
Other classes have no meaningful textual representation
that a program will care about.
Such classes will typically override toString
to provide
useful information when inspecting the object,
mainly for debugging or logging.
Implementation
@override
String toString() {
if (key.isNullOrEmpty) {
throw InvalidAtKeyException('Key cannot be null or empty');
}
//enforcing lower-case on AtKey.key
key = key.toLowerCase();
// If metadata.isPublic is true and metadata.isCached is true,
// return cached public key
if (key.startsWith('cached:public:') ||
(metadata.isPublic) && (metadata.isCached)) {
return 'cached:public:$key${_dotNamespaceIfPresent()}$_sharedBy';
}
// If metadata.isPublic is true, return public key
if (key.startsWith('public:') || (metadata.isPublic)) {
return 'public:$key${_dotNamespaceIfPresent()}$_sharedBy';
}
//If metadata.isCached is true, return shared cached key
if (key.startsWith('cached:') || (metadata.isCached)) {
return 'cached:$_sharedWith:$key${_dotNamespaceIfPresent()}$_sharedBy';
}
// If key starts with privatekey:, return private key
if (metadata.isHidden || key.startsWith('privatekey:')) {
if (key.startsWith('privatekey:')) {
return key.toLowerCase();
}
return 'privatekey:$key${_dotNamespaceIfPresent()}'.toLowerCase();
}
//If _sharedWith is not null, return sharedKey
if (_sharedWith != null && _sharedWith!.isNotEmpty) {
return '$_sharedWith:$key${_dotNamespaceIfPresent()}$_sharedBy';
}
// if key starts with local: or isLocal set to true, return local key
if (isLocal == true) {
String localKey = '$key${_dotNamespaceIfPresent()}$sharedBy';
if (localKey.startsWith('local:')) {
return localKey;
}
return 'local:$localKey';
}
// Defaults to return a self key.
return '$key${_dotNamespaceIfPresent()}$_sharedBy';
}