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/scanned_barcode_label.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/pattern.dart'; import 'package:lottis_birthday_escaperoom_app/util.dart'; import 'package:mobile_scanner/mobile_scanner.dart'; class QrScreen extends StatelessWidget { const QrScreen({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 2'), 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: [ Text(c.storyTitle, style: Theme.of(context).textTheme.titleLarge), const SizedBox(height: 8), Container( height: 600, decoration: BoxDecoration( border: Border.all(color: Colors.grey), borderRadius: BorderRadius.circular(10), ), child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(8.0), child: Text( c.story, style: const TextStyle(fontSize: 20), ), ), ), ), const SizedBox(height: 20), const Center( child: Text('Zum entsperren, bitte QR Code scannen.'), ), Container( height: 300, child: MobileScanner( fit: BoxFit.contain, controller: c.qrPageController, errorBuilder: (context, error, child) { return ScannerErrorWidget(error: error); }, overlayBuilder: (context, constraints) { return Align( alignment: Alignment.center, child: Container( height: 200, 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 (barcode.rawValue == c.calendarQrData) { c.qrPageController.stop(); Get.offAll(PatternScreen()); } else { Get.snackbar("Falscher Code", "Der Code '${barcode.rawValue}' ist falsch."); } } } }, ), ), ], ), ), ), ); } }