create static method

NdefRecord create({
  1. required Uri uri,
  2. String? title,
  3. String titleLanguageCode = 'en',
  4. SmartPosterAction? action,
  5. String? iconMimeType,
  6. Uint8List? iconData,
})

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(),
  );
}