Skip to content

Colours and texts ​

Every scanner reads a ScannerTheme for its colours and shapes and a ScannerStrings for its texts. Set them on one scanner, or once for the whole app.

The theme ​

dart
BarcodeScanner(
  template: const ScannerTemplate.minimal(),
  theme: const ScannerTheme(
    accent: Color(0xFFFF6A1A),
    windowRadius: 6,
    buttonShape: ScannerButtonShape.roundedSquare,
  ),
  onDetect: (capture) => print(capture.barcode.content),
)

Every field is optional: what you leave out comes from the template's theme, then from a ScannerScope, then from the defaults.

FieldDefaultWhat it does
accentScannerTheme.defaultAccent, a bright tealThe colour of a locked code: the brackets, the outlines and the main buttons. Text in this colour gets enough contrast by itself.
brightnessthe platform'sLight or dark glass
windowRadius24Corner radius of the scan window
buttonShapeScannerButtonShape.circleRound buttons, or roundedSquare for brands with sharper shapes
bluron, off when the device is too slowWhether the glass blurs the camera behind it. Left unset, the scanner stops blurring for good when, in its first three seconds, the device has no room for it (one frame in ten over 8 ms, or five over 16 ms); true blurs always, false never
scrimBluron, off when the device is too slowWhether the dimmed camera around the window is blurred too; it is computed again for every frame. Unset, true and false work as for blur
fontFamilythe app'sFont of the scanner's text
monoFontFamilya monospaced system fontFont of barcode data
warningamberA code that needs a look (ScanVerdict.warn)
dangera bright redA refused code (ScanVerdict.reject) and problems such as an expired date

The whole app ​

A ScannerScope gives every scanner below it, scanBarcode and ScanFieldButton included, a theme and texts. Put it in your app's builder to follow its colours and language:

dart
MaterialApp(
  builder: (context, child) => ScannerScope(
    theme: ScannerTheme(
      accent: Theme.of(context).colorScheme.primary,
      brightness: Theme.of(context).brightness,
    ),
    strings: const ScannerStrings(close: 'Scanner schließen', scanAgain: 'Weiter'),
    child: child!,
  ),
)

A template's theme applies over the scope's, and the scanner's own theme and strings over both.

Texts and languages ​

ScannerStrings holds every text of the scanner in English: buttons, hints, errors, the result sheet and the template titles. Translate the ones your app shows; the rest stay English.

dart
const ScannerStrings german = ScannerStrings(
  close: 'Schließen',
  torchOn: 'Licht an',
  torchOff: 'Licht aus',
  scanAgain: 'Weiter scannen',
  copy: 'Kopieren',
  hintQrCode: 'Auf einen QR-Code richten',
);

final ScannerStrings mine = german.copyWith(close: 'Zurück');

The hints and titles of the templates are strings too (hintQrCode, hintBarcode, hintTicket, titlePayment, titleTicket…), so a template speaks the app's language without changing the template.