import 'package:flutter/material.dart'; import 'package:get/get.dart'; // import 'package:qr_code_scanner/qr_code_scanner.dart'; import '../../../custom_widgets/custom_app_bar.dart'; import '../controllers/qr_setting_controller.dart'; class QrScanScreen extends GetView { const QrScanScreen({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: DashBoardAppBar( onBackButtonPressed: () { Get.back(); }, title: "QR SCAN", ), body: GetBuilder(builder: (controller) { return Column( children: [ // Expanded( // flex: 5, // child: QRView( // key: controller.qrKey, // onQRViewCreated: controller.onQRViewCreated, // overlay: QrScannerOverlayShape(), // ), // ), Expanded( child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ GestureDetector( onTap: () async { await controller.scanfromImage(); }, child: const Icon(Icons.image)), GestureDetector( onTap: () { controller.toggleFlash(); }, child: FutureBuilder( future: controller.getFlashStatus(), builder: (context, snapshot) { return Icon( (snapshot.data ?? false) ? Icons.flash_off : Icons.flash_on, ); }, ), ), ], )), ], ); }), ); } } // // // import 'dart:async'; // // // import 'package:flutter/material.dart'; // // import 'package:get/get.dart'; // // import 'package:qr_flutter/qr_flutter.dart'; // // import 'package:uco_ciihive/app/core/utils/logs_utils.dart'; // // import 'package:uco_ciihive/app/custom_widgets/custom_app_bar.dart'; // // import 'package:mobile_scanner/mobile_scanner.dart'; // // import 'scanner_buttons.dart'; // // // class QrScanScreen extends StatefulWidget { // // const QrScanScreen({super.key}); // // // @override // // State createState() => _QrScanScreenState(); // // } // // // class _QrScanScreenState extends State { // // // // // // final MobileScannerController scanController = MobileScannerController( // // formats: [BarcodeFormat.qrCode], // // useNewCameraSelector: true, // // facing: CameraFacing.back, // // ); // // // StreamSubscription? _subscription; // // // late final AppLifecycleListener _listener; // // // Barcode? _barcode; // // // @override // // void initState() { // // // initScanner(); // // listenAppLifeState(); // // // super.initState(); // // } // // // @override // // Future dispose() async { // // unawaited(_subscription?.cancel()); // // _subscription = null; // // _listener.dispose(); // // // super.dispose(); // // // await scanController.dispose(); // // } // // // void listenAppLifeState() { // // _listener = AppLifecycleListener( // // onStateChange: _onStateChanged, // // ); // // } // // // void initScanner() { // // _subscription = scanController.barcodes.listen(_handleBarcode); // // // unawaited(scanController.start()); // // } // // // Future _onStateChanged(AppLifecycleState state) async { // // dp("Scanner state", state.name); // // switch (state) { // // case AppLifecycleState.hidden: // // case AppLifecycleState.paused: // // case AppLifecycleState.detached: // // return; // // case AppLifecycleState.resumed: // // _subscription = scanController.barcodes.listen(_handleBarcode); // // // unawaited(scanController.start()); // // case AppLifecycleState.inactive: // // unawaited(_subscription?.cancel()); // // _subscription = null; // // unawaited(scanController.stop()); // // } // // } // // // void _handleBarcode(BarcodeCapture barcodes) { // // _barcode = barcodes.barcodes.firstOrNull; // // dp("Barcode Result Raw", _barcode?.rawValue); // // dp("Barcode Display Value", _barcode?.displayValue); // // // setState(() {}); // // } // // // @override // // Widget build(BuildContext context) { // // final scanWindow = Rect.fromCenter( // // center: MediaQuery.sizeOf(context).center(Offset.zero), // // width: 200, // // height: 200, // // ); // // return Scaffold( // // appBar: DashBoardAppBar( // // onBackButtonPressed: () { // // Get.back(); // // }, // // ), // // body: Stack( // // fit: StackFit.expand, // // children: [ // // Center( // // child: MobileScanner( // // fit: BoxFit.contain, // // controller: scanController, // // scanWindow: scanWindow, // // errorBuilder: (context, error, child) { // // // return ScannerErrorWidget(error: error); // // return const SizedBox( // // child: Text("Error Widget"), // // ); // // }, // // overlayBuilder: (context, constraints) { // // return Padding( // // padding: const EdgeInsets.all(16.0), // // child: Align( // // alignment: Alignment.bottomCenter, // // child: // // ScannedBarcodeLabel(barcodes: scanController.barcodes), // // ), // // ); // // }, // // ), // // ), // // ValueListenableBuilder( // // valueListenable: scanController, // // builder: (context, value, child) { // // if (!value.isInitialized || // // !value.isRunning || // // value.error != null) { // // return const SizedBox( // // child: Text("No init Scanner"), // // ); // // } // // // return CustomPaint( // // painter: ScannerOverlay(scanWindow: scanWindow), // // ); // // }, // // ), // // Align( // // alignment: Alignment.bottomCenter, // // child: Padding( // // padding: const EdgeInsets.all(16.0), // // child: Row( // // mainAxisAlignment: MainAxisAlignment.spaceEvenly, // // children: [ // // ToggleFlashlightButton(controller: scanController), // // SwitchCameraButton(controller: scanController), // // ], // // ), // // ), // // ), // // ], // // ), // // ); // // } // // } // // // class ScannerOverlay extends CustomPainter { // // const ScannerOverlay({ // // required this.scanWindow, // // this.borderRadius = 12.0, // // }); // // // final Rect scanWindow; // // final double borderRadius; // // // @override // // void paint(Canvas canvas, Size size) { // // // TODO: use `Offset.zero & size` instead of Rect.largest // // // we need to pass the size to the custom paint widget // // final backgroundPath = Path()..addRect(Rect.largest); // // // final cutoutPath = Path() // // ..addRRect( // // RRect.fromRectAndCorners( // // scanWindow, // // topLeft: Radius.circular(borderRadius), // // topRight: Radius.circular(borderRadius), // // bottomLeft: Radius.circular(borderRadius), // // bottomRight: Radius.circular(borderRadius), // // ), // // ); // // // final backgroundPaint = Paint() // // ..color = Colors.black.withOpacity(0.5) // // ..style = PaintingStyle.fill // // ..blendMode = BlendMode.dstOut; // // // final backgroundWithCutout = Path.combine( // // PathOperation.difference, // // backgroundPath, // // cutoutPath, // // ); // // // final borderPaint = Paint() // // ..color = Colors.white // // ..style = PaintingStyle.stroke // // ..strokeWidth = 4.0; // // // final borderRect = RRect.fromRectAndCorners( // // scanWindow, // // topLeft: Radius.circular(borderRadius), // // topRight: Radius.circular(borderRadius), // // bottomLeft: Radius.circular(borderRadius), // // bottomRight: Radius.circular(borderRadius), // // ); // // // // First, draw the background, // // // with a cutout area that is a bit larger than the scan window. // // // Finally, draw the scan window itself. // // canvas.drawPath(backgroundWithCutout, backgroundPaint); // // canvas.drawRRect(borderRect, borderPaint); // // } // // // @override // // bool shouldRepaint(ScannerOverlay oldDelegate) { // // return scanWindow != oldDelegate.scanWindow || // // borderRadius != oldDelegate.borderRadius; // // } // // } // // // class ScannedBarcodeLabel extends StatelessWidget { // // const ScannedBarcodeLabel({ // // super.key, // // required this.barcodes, // // }); // // // final Stream 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.wh'ite), // // ); // // } // // // return Text( // // scannedBarcodes.first.displayValue ?? 'No display value.', // // overflow: TextOverflow.fade, // // style: const TextStyle(color: Colors.white), // // ); // // }, // // ); // // } // // }