emvqr 0.0.8
emvqr: ^0.0.8 copied to clipboard
A plugin by Fawry for scanning EMV QR Codes.
example/lib/main.dart
import 'dart:async';
import 'package:emvqr/model/scan_result.dart';
import 'package:flutter/material.dart';
import 'package:emvqr/emvqr.dart';
import 'package:emvqr/model/qr_model.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Fawry SDK Flutter',
theme: ThemeData(
useMaterial3: true,
),
darkTheme: ThemeData.dark(
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late StreamSubscription? _fawryCallbackResultStream;
QrModel? qrModel;
ScanResult? qrResponse;
@override
void initState() {
super.initState();
setupCallback();
}
@override
void dispose() {
_fawryCallbackResultStream?.cancel();
super.dispose();
}
Future<void> setupCallback() async {
try {
_fawryCallbackResultStream =
Emvqr.instance.callbackResultStream().listen((event) {
setState(() {
Map<Object?, Object?> eventData = event;
ScanResult response = ScanResult.fromJson(eventData);
QrModel? model = response.extractQrModel();
qrResponse = response;
qrModel = model ?? qrModel;
if (qrModel != null) {
debugPrint(qrModel.toString());
}
});
});
} catch (ex) {
debugPrint("Error in setupCallback: $ex");
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('Fawry EMVQR example'),
),
body: SingleChildScrollView(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () async {
await startScanning();
},
child: const Text('SCAN'),
),
const SizedBox(
height: 20),
const Text(
'QR Model',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
if (qrModel != null) SelectableText(qrModel.toString()),
const SizedBox(height: 10),
const Text(
'Response Status',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
SelectableText('${qrResponse?.status}'),
const SizedBox(height: 10),
const Text(
'Response Data',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
SelectableText('${qrResponse?.data}'),
const SizedBox(height: 300),
],
),
),
),
);
}
Future<void> startScanning() async {
await Emvqr.instance.scanQR();
}
}