Skip to content

What is in a code ​

barcode.content parses what a code holds into a BarcodeContent: a link, a Wi-Fi network, a contact, a payment… Parsing never throws: anything it does not recognise is TextContent or BinaryContent.

dart
void handle(Barcode barcode) {
  switch (barcode.content) {
    case UrlContent(:final url):
      launchUrl(url);
    case WifiContent(:final ssid, :final password):
      print('Join $ssid with $password');
    case ContactContent contact:
      print('Save ${contact.name}');
    case Gs1Content(:final gtin):
      print('Look up $gtin');
    default: // new kinds come in minor versions
      print(barcode.text);
  }
}

New kinds come in minor versions, so a switch over BarcodeContent or PaymentContent needs a default.

Open it ​

content.uri is a link to open the content with url_launcher: https://, mailto:, tel:, sms:, geo:… It is null for kinds without a link, such as Wi-Fi networks and contacts.

dart
Future<void> open(Barcode barcode) async {
  if (barcode.content.uri case final Uri uri) {
    await launchUrl(uri);
  }
}

The kinds ​

Built means the kind has a toPayload() that writes the standard format, see Building content. Parsed only kinds come from codes that others issue (airlines, states, device makers); their toPayload() returns the text as read.

KindHoldsPayloadBuilt
TextContenttextas isyes
UrlContenturl, title, servicehttps://…; MEBKM: with a titleyes
WifiContentssid, password, security (open, WEP, WPA, WPA3), hiddenWIFI:T:WPA;S:…;P:…;;yes
ContactContentname, organization, title, phones, e-mails, web addresses, addresses, note, birthDatevCard 3.0, or MECARD:yes
EventContenttitle, start, end, all day, location, descriptionBEGIN:VCALENDAR with one VEVENTyes
EmailContentrecipients, subject, bodymailto:yes
PhoneContentnumber; phone or FaceTimetel:, facetime:, facetime-audio:yes
SmsContentrecipients, messageSMSTO:number:messageyes
GeoContentlatitude, longitude, altitude, searchgeo:yes
OtpContentsecret, account, issuer, TOTP or HOTP, algorithm, digits, period, counterotpauth://totp/…yes
EsimContentSM-DP+ address, Matching ID, OID, confirmation codeLPA:1$…yes
CryptoContentnetwork, address, amount in coins, value as written (wei), label, message, chain idbitcoin:, litecoin:, ethereum:, lightning:yes
Gs1ContentApplication Identifiers and values; gtin, expiryDate, bestBeforeDate…GS1 element stringsyes, with encodeContent or gs1: true
BinaryContentbytesbinarywith encodeContent or BarcodeView.bytes
PaymentContentpayee, account, amount, currency, reference; a kind per standardsee Paymentsyes
WifiDppContentpublic key, channels, MAC address, informationDPP:…;; (Wi‑Fi Easy Connect)parsed only
SmartHomeContentMatter or HomeKit; setup code, vendor and product id, discriminator, category, setup idMT:…, X-HM://…parsed only
ProductContentgtin (always a GTIN-14), number as printed, add-on; ISBN-13, ISBN-10, ISSNEAN-13, EAN-8, UPC-A, UPC-E barcodesparsed only
BoardingPassContentpassenger, legs: booking, from, to, carrier, flight, day, cabin, seat, sequenceIATA BCBP (M1…)parsed only
DriverLicenseContentnumber, names, birthDate, issue and expiryDate, address, state, countryAAMVA DL/ID (PDF417)parsed only
VinContentVIN, WMI, region, model year, check digit17 characters (ISO 3779)parsed only

ProductContent comes only from EAN and UPC codes, and Gs1Content and BinaryContent only from codes marked GS1 or binary.

Text you already have ​

BarcodeContent.parseText parses text that did not come from a scan, such as a saved history entry:

dart
final BarcodeContent content = BarcodeContent.parseText('WIFI:T:WPA;S:Home;P:secret;;');

It cannot tell GS1, binary and product codes apart in a saved string: those come only from barcode.content.

Privacy ​

OtpContent holds a secret that logs in as the account's second factor, and DriverLicenseContent personal data. Their toString() leaves these out, and the scanner's result sheet does not show an OTP secret.