BarcodeContent class sealed
The payload of a Barcode, parsed into a typed value.
Get it with BarcodeContentOf.content (barcode.content) and use pattern matching:
switch (barcode.content) {
case UrlContent(:final url): openUrl(url);
case WifiContent(:final ssid, :final password): connect(ssid, password);
case ContactContent contact: saveContact(contact);
case Gs1Content(:final elements): print(elements['01']); // GTIN
default: print(barcode.text);
}
Recognised formats:
| Content | Payload |
|---|---|
| UrlContent | https://…, http://…, www.…, MEBKM:, URLTO: |
| WifiContent | WIFI:T:WPA;S:name;P:password;; |
| ContactContent | vCard 2.1/3.0/4.0, MECARD: |
| EventContent | BEGIN:VEVENT, alone or in a VCALENDAR |
| EmailContent | mailto:, MATMSG:, SMTP: |
| PhoneContent | tel: |
| SmsContent | sms:, smsto:, mms:, mmsto: |
| GeoContent | geo: |
| PaymentContent | EPC/SEPA (BCD), Swiss QR-bill (SPC), ГОСТ Р 56042 (ST0001), UPI, EMVCo (PIX, PayNow, PromptPay…), SPAYD |
| OtpContent | otpauth://totp/…, otpauth://hotp/… |
| EsimContent | LPA:1$… |
| CryptoContent | bitcoin:, ethereum:, litecoin:, lightning:, lnbc… |
| WifiDppContent | DPP: (Wi-Fi Easy Connect) |
| SmartHomeContent | MT: (Matter), X-HM:// (HomeKit) |
| BoardingPassContent | IATA boarding passes (M1…) |
| DriverLicenseContent | AAMVA driver's licenses and IDs (@…ANSI …) |
| VinContent | vehicle identification numbers |
| ProductContent | EAN/UPC barcodes: GTIN, ISBN, ISSN |
| Gs1Content | GS1 barcodes (BarcodeContentType.gs1) |
| BinaryContent | binary barcodes (BarcodeContentType.binary) |
Parsing never throws: anything not recognised, or recognised but malformed, is TextContent.
The other way round, toPayload builds the text to put in a barcode, with the escaping each format needs:
const WifiContent wifi = WifiContent(ssid: 'Home', password: 'secret12');
BarcodeView(wifi.toPayload()); // WIFI:T:WPA;S:Home;P:secret12;;
- Implementers
- Annotations
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toPayload(
) → String -
The text to put in a barcode:
WIFI:…, a vCard,mailto:…and so on. -
toString(
) → String -
A string representation of this object.
inherited
-
validate(
) → List< ContentIssue> - The problems that keep toPayload from building this value, such as an empty network name or a latitude out of range. Empty when the value can be built. For forms: show each ContentIssue.message next to its ContentIssue.field.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
parse(
Barcode barcode) → BarcodeContent -
Parses the payload of
barcode.barcode.contentcalls this once per barcode and keeps the result. -
parseText(
String text) → BarcodeContent - Parses a payload that is only available as text, for example one saved earlier. Never returns Gs1Content or BinaryContent: whether a payload is GS1 or binary is known only from the barcode itself.