import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:lottis_birthday_escaperoom_app/controller/gamecontroller.dart'; import 'package:lottis_birthday_escaperoom_app/scanner_error_widget.dart'; import 'package:lottis_birthday_escaperoom_app/screens/admin.dart'; import 'package:lottis_birthday_escaperoom_app/screens/qr.dart'; import 'package:lottis_birthday_escaperoom_app/util.dart'; import 'package:mobile_scanner/mobile_scanner.dart'; class MarkerScreen extends StatelessWidget { const MarkerScreen({Key? key}) : super(key: key); @override Widget build(BuildContext context) { GameController c = Get.find(); return PopScope( canPop: false, child: Scaffold( appBar: AppBar( title: const Text('Lotti\'s Escape Room - Rätsel 1'), actions: [ IconButton( icon: const Icon(Icons.smart_toy_outlined), onPressed: () { showAdminLoginPopup(); }, ), ], ), body: Padding( padding: const EdgeInsets.all(16.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const Center( child: Text('Zum entsperren, bitte Code eingeben.'), ), TextField( decoration: const InputDecoration( labelText: 'Code', ), keyboardType: TextInputType.text, controller: c.markerSequenceController, ), ElevatedButton( onPressed: () { if (c.checkMarkerString()) { Get.offAll(const QrScreen()); } else { Get.snackbar("Falscher Code", "Der Code '${c.markerSequenceController.text}' ist falsch."); } }, child: const Text('Code eingeben'), ), Container( height: 400, child: MobileScanner( fit: BoxFit.contain, controller: c.markerPageScannerController, errorBuilder: (context, error, child) { return ScannerErrorWidget(error: error); }, overlayBuilder: (context, constraints) { return Align( alignment: Alignment.center, child: Container( height: 60, width: 200, decoration: BoxDecoration( border: Border.all( color: Colors.white, width: 3, ), borderRadius: BorderRadius.circular(10), ), )); }, onDetect: (barcodes) { if (barcodes.barcodes.isNotEmpty) { for (var barcode in barcodes.barcodes) { if (barcode.rawValue == null) { continue; } playBeepSound(); if (c.markerNumbersToDeclaration.keys .contains(barcode.rawValue)) { c.markerSequenceController.text = "${c.markerSequenceController.text}${c.markerNumbersToDeclaration[barcode.rawValue]}"; } else { Get.snackbar("Unbekannter Code", "Der Code '${barcode.rawValue}' konnte nicht erkannt werden.\nProbiere es doch nochmal :)"); } c.markerPageScannerController.stop(); } } }, ), ), ElevatedButton( onPressed: () { // start scanner if (c.markerPageScannerController.value.isRunning) { c.markerPageScannerController.stop(); } else { c.markerPageScannerController.start(); } }, child: const Text('Barcode\nscannen'), ), ], ), ), ), ); } }