Showing
1 changed file
with
35 additions
and
0 deletions
example/lib/scanned_barcode_label.dart
0 → 100644
| 1 | +import 'package:flutter/material.dart'; | ||
| 2 | +import 'package:mobile_scanner/mobile_scanner.dart'; | ||
| 3 | + | ||
| 4 | +class ScannedBarcodeLabel extends StatelessWidget { | ||
| 5 | + const ScannedBarcodeLabel({ | ||
| 6 | + super.key, | ||
| 7 | + required this.barcodes, | ||
| 8 | + }); | ||
| 9 | + | ||
| 10 | + final Stream<BarcodeCapture> barcodes; | ||
| 11 | + | ||
| 12 | + @override | ||
| 13 | + Widget build(BuildContext context) { | ||
| 14 | + return StreamBuilder( | ||
| 15 | + stream: barcodes, | ||
| 16 | + builder: (context, snaphot) { | ||
| 17 | + final scannedBarcodes = snaphot.data?.barcodes ?? []; | ||
| 18 | + | ||
| 19 | + if (scannedBarcodes.isEmpty) { | ||
| 20 | + return const Text( | ||
| 21 | + 'Scan something!', | ||
| 22 | + overflow: TextOverflow.fade, | ||
| 23 | + style: TextStyle(color: Colors.white), | ||
| 24 | + ); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + return Text( | ||
| 28 | + scannedBarcodes.first.displayValue ?? 'No display value.', | ||
| 29 | + overflow: TextOverflow.fade, | ||
| 30 | + style: const TextStyle(color: Colors.white), | ||
| 31 | + ); | ||
| 32 | + }, | ||
| 33 | + ); | ||
| 34 | + } | ||
| 35 | +} |
-
Please register or login to post a comment