NdefRecord.createMime constructor

NdefRecord.createMime(
  1. String type,
  2. Uint8List data
)

Constructs an instance containing media data as defined by RFC 2046.

Implementation

factory NdefRecord.createMime(String type, Uint8List data) {
  type = type.toLowerCase().trim().split(';').first;
  if (type.isEmpty) throw ('type is empty');

  final slashIndex = type.indexOf('/');
  if (slashIndex == 0) throw ('type must have mojor type');
  if (slashIndex == type.length - 1) throw ('type must have minor type');

  return NdefRecord(
    typeNameFormat: NdefTypeNameFormat.media,
    type: ascii.encode(type),
    identifier: Uint8List.fromList([]),
    payload: data,
  );
}