113 lines
2.9 KiB
Dart
113 lines
2.9 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:cathaypay_mobile/Pay/PayQr.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 QrScanDialog extends StatefulWidget {
|
|
const QrScanDialog({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<QrScanDialog> createState() => _PayPageState();
|
|
}
|
|
|
|
class _PayPageState extends State<QrScanDialog> {
|
|
@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);
|
|
var spl = scanData.code?.split("|");
|
|
if (spl != null && spl.isNotEmpty) {
|
|
showModalBottomSheet(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
useSafeArea: true,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.vertical(
|
|
top: Radius.circular(16),
|
|
),
|
|
),
|
|
builder: (BuildContext context) {
|
|
return PayQrPage(code: spl);
|
|
}).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),
|
|
),
|
|
));
|
|
}
|
|
}
|