create static method
Builds a smart poster record.
Implementation
static NdefRecord create({
required Uri uri,
String? title,
String titleLanguageCode = 'en',
SmartPosterAction? action,
String? iconMimeType,
Uint8List? iconData,
}) {
if ((iconMimeType == null) != (iconData == null)) {
throw ArgumentError('iconMimeType and iconData must be given together');
}
// The nested message must begin with the URI record; everything else is optional.
final nested = <NdefRecord>[
UriRecord.create(uri),
if (title != null) TextRecord.create(title, languageCode: titleLanguageCode),
if (action != null)
NdefRecord(
typeNameFormat: NdefTypeNameFormat.wellKnown,
type: Uint8List.fromList(ascii.encode('act')),
identifier: Uint8List(0),
payload: Uint8List.fromList([action.index]),
),
if (iconMimeType != null && iconData != null) MimeRecord.create(iconMimeType, iconData),
];
return NdefRecord(
typeNameFormat: NdefTypeNameFormat.wellKnown,
type: NdefRecord.wellKnownTypeSmartPoster,
identifier: Uint8List(0),
payload: NdefMessage(nested).toBytes(),
);
}