import 'dart:io'; import 'package:cathaypay_mobile/Pay/PayThaiQr.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:qr_code_scanner/qr_code_scanner.dart'; class ThaiQrDialog extends StatefulWidget { const ThaiQrDialog({Key? key}) : super(key: key); @override State createState() => _PayPageState(); } class _PayPageState extends State { @override void initState() { super.initState(); } // { // "MobileDeviceNo": "string", "TransactionID": "string", "Amount": 0, // "Note": "string" // } final GlobalKey qrKey = GlobalKey(debugLabel: 'QR'); Barcode? result; QRViewController? controller; // In order to get hot reload to work we need to pause the camera if the platform // is android, or resume the camera if the platform is iOS. @override void reassemble() { super.reassemble(); if (Platform.isAndroid) { controller!.pauseCamera(); } else if (Platform.isIOS) { controller!.resumeCamera(); } } var isReturn = false; void _onQRViewCreated(QRViewController controller) { this.controller = controller; controller.scannedDataStream.listen((scanData) { print(scanData.code); showModalBottomSheet( context: context, isScrollControlled: true, useSafeArea: true, shape: const RoundedRectangleBorder( borderRadius: BorderRadius.vertical( top: Radius.circular(16), ), ), builder: (BuildContext context) { return PayThaiQr(code: scanData.code ?? ""); }).whenComplete(() { controller.resumeCamera(); }); controller.pauseCamera(); }); } @override void dispose() { controller?.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return SafeArea( child: Scaffold( appBar: AppBar( backgroundColor: Colors.transparent, flexibleSpace: Image( image: AssetImage('images/home/Head.png'), fit: BoxFit.cover, ), leading: CupertinoButton( onPressed: () { Navigator.pop(context); }, child: const Icon( Icons.chevron_left, color: Colors.white, ), ), elevation: 0, title: Text( "Scan QR Code".tr(), textAlign: TextAlign.center, style: GoogleFonts.kanit( color: Colors.white, fontSize: 20, ), ), ), body: Container( width: MediaQuery.of(context).size.width, child: QRView(key: qrKey, onQRViewCreated: _onQRViewCreated), ), )); } }