create static method
Builds a media record. Parameters after ; are dropped, since NDEF stores the bare
type.
Implementation
static NdefRecord create(String mimeType, Uint8List data) {
final normalized = mimeType.toLowerCase().trim().split(';').first;
if (normalized.isEmpty) throw ArgumentError.value(mimeType, 'mimeType', 'is empty');
final slashIndex = normalized.indexOf('/');
if (slashIndex <= 0) throw ArgumentError.value(mimeType, 'mimeType', 'must have a major type');
if (slashIndex == normalized.length - 1) throw ArgumentError.value(mimeType, 'mimeType', 'must have a minor type');
// As in TextRecord.create: an RFC 2046 media type is ASCII, and reporting it here beats
// letting `ascii.encode` below raise an error that names neither the parameter nor the rule.
if (normalized.codeUnits.any((unit) => unit > 0x7F)) {
throw ArgumentError.value(mimeType, 'mimeType', 'is not an ASCII media type');
}
return NdefRecord(
typeNameFormat: NdefTypeNameFormat.media,
type: ascii.encode(normalized),
identifier: Uint8List(0),
payload: data,
);
}