import 'package:flutter/material.dart'; import 'package:mobile_scanner/mobile_scanner.dart'; class BarcodeScannerScreen extends StatefulWidget { const BarcodeScannerScreen({super.key}); @override State createState() => _BarcodeScannerScreenState(); } class _BarcodeScannerScreenState extends State { bool _handled = false; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Escanear código')), body: Stack( children: [ MobileScanner( onDetect: (capture) { if (_handled) return; final barcode = capture.barcodes.isNotEmpty ? capture.barcodes.first.rawValue : null; if (barcode == null || barcode.isEmpty) return; _handled = true; Navigator.of(context).pop(barcode); }, ), // Visual guide overlay Center( child: Container( width: 240, height: 160, decoration: BoxDecoration( border: Border.all(color: Colors.white, width: 2), borderRadius: BorderRadius.circular(12), ), ), ), Positioned( bottom: 48, left: 0, right: 0, child: Center( child: Container( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), decoration: BoxDecoration( color: Colors.black54, borderRadius: BorderRadius.circular(20), ), child: const Text( 'Apunta el código de barras hacia el recuadro', style: TextStyle(color: Colors.white, fontSize: 13), ), ), ), ), ], ), ); } }