36 lines
902 B
Dart
36 lines
902 B
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:mobile_scanner/mobile_scanner.dart';
|
||
|
|
||
|
class ScannedBarcodeLabel extends StatelessWidget {
|
||
|
const ScannedBarcodeLabel({
|
||
|
super.key,
|
||
|
required this.barcodes,
|
||
|
});
|
||
|
|
||
|
final Stream<BarcodeCapture> barcodes;
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return StreamBuilder(
|
||
|
stream: barcodes,
|
||
|
builder: (context, snapshot) {
|
||
|
final scannedBarcodes = snapshot.data?.barcodes ?? [];
|
||
|
|
||
|
if (scannedBarcodes.isEmpty) {
|
||
|
return const Text(
|
||
|
'Scan something!',
|
||
|
overflow: TextOverflow.fade,
|
||
|
style: TextStyle(color: Colors.white),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return Text(
|
||
|
scannedBarcodes.first.displayValue ?? 'No display value.',
|
||
|
overflow: TextOverflow.fade,
|
||
|
style: const TextStyle(color: Colors.white),
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
}
|