NdefRecord.createText constructor

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

Constructs an instance containing UTF-8 text.

Can specify the languageCode for the given text, en by default.

Implementation

factory NdefRecord.createText(String text, {String languageCode = 'en'}) {
  final languageCodeBytes = ascii.encode(languageCode);
  if (languageCodeBytes.length >= 64) throw ('languageCode is too long');

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