create static method

NdefRecord create(
  1. String text, {
  2. String languageCode = 'en',
})

Builds a well-known text record. Always encodes as UTF-8.

Implementation

static NdefRecord create(String text, {String languageCode = 'en'}) {
  final languageCodeBytes = ascii.encode(languageCode);
  // The status byte packs the length into six bits, so 63 is the ceiling.
  if (languageCodeBytes.length > 63) throw ArgumentError.value(languageCode, 'languageCode', 'is too long');

  return NdefRecord(
    typeNameFormat: NdefTypeNameFormat.wellKnown,
    type: NdefRecord.wellKnownTypeText,
    identifier: Uint8List(0),
    payload: Uint8List.fromList([languageCodeBytes.length, ...languageCodeBytes, ...utf8.encode(text)]),
  );
}