from static method
Reads record as a URI record, or returns null when it is not one or is malformed.
Also accepts NdefTypeNameFormat.absoluteUri, where the URI is the type field and there is no prefix byte.
Implementation
static UriRecord? from(NdefRecord record) {
if (record.typeNameFormat == NdefTypeNameFormat.absoluteUri) {
return _parse(utf8.decode(record.type, allowMalformed: true));
}
if (record.typeNameFormat != NdefTypeNameFormat.wellKnown) return null;
if (!_bytesEqual(record.type, NdefRecord.wellKnownTypeUri)) return null;
// The prefix byte alone is not a URI; a record carrying only it holds nothing to resolve.
if (record.payload.length < 2) return null;
final prefixIndex = record.payload[0];
// A prefix index this version does not know cannot be resolved; the rest of the payload
// alone would be a different URI, so report "not a URI record" rather than guess.
if (prefixIndex >= NdefRecord.uriPrefixList.length) return null;
return _parse(
'${NdefRecord.uriPrefixList[prefixIndex]}'
'${utf8.decode(record.payload.sublist(1), allowMalformed: true)}',
);
}