Skip to content

Commit

Permalink
Try flutter_zxing instead
Browse files Browse the repository at this point in the history
  • Loading branch information
sukso96100 committed Aug 3, 2023
1 parent 6ad917c commit 1e116fc
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 55 deletions.
114 changes: 59 additions & 55 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:io' show Platform;

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_zxing/generated_bindings.dart';
import 'package:yaru/yaru.dart';
import 'package:quick_usb/quick_usb.dart';
import 'package:flutter_gstreamer_player/flutter_gstreamer_player.dart';
Expand All @@ -15,6 +16,7 @@ import 'imgutil.dart';
import 'tsplutils.dart';
import 'kioskclient.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_zxing/flutter_zxing.dart' as zx;

void main() {
runApp(const MyApp());
Expand Down Expand Up @@ -146,71 +148,73 @@ class _KioskMainPageState extends State<KioskMainPage> {
cameraKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
ui.Image image = await boundary.toImage();

final qrCode = qrvision.QrCode();
final byteData =
(await image.toByteData(format: ui.ImageByteFormat.rawRgba))!
.buffer
.asUint8List();
qrCode.scanRgbaBytes(byteData, image.width, image.height);

if (qrCode.location != null) {
// print('QR code here: ${qrCode.location}');
if (qrCode.content != null) {
try {
print('QR Content found!');
print('QR Content: ${qrCode.content?.text}');
var qrContent = qrCode.content!.text;
if (!isKioskConfigured) {
try {
var clientConfig = jsonDecode(qrContent);
if (clientConfig.containsKey('config_endpoint') &&
clientConfig.containsKey('token')) {
setState(() {
nametagRole = "키오스크 설정 중입니다.";
});
await configureKiosk(
clientConfig['config_endpoint'], clientConfig['token']);
Map<String, String> envVars = Platform.environment;
final SharedPreferences prefs =
await SharedPreferences.getInstance();
var newKioskClient = KioskClient(
envVars['HOME']! + "/ubuntu_kr_qr_kiosk_check_in_db.db",
prefs.getString('host') ?? '',
prefs.getString('apiToken') ?? '',
prefs.getString('jwtKey') ?? '',
prefs.getString('jwtKeyAlgo') ?? '');
setState(() {
isKioskConfigured = true;
nametagRole = "체크인 QR을 스캔하세요.";
kioskClient = newKioskClient;
});
}
} on Exception catch (e) {
print(e);
}
} else {
setState(() {
isProcessingQrCheckin = true;
});
var (result, payload) = kioskClient.checkInLocally(qrContent);
setState(() {
nametagName = payload['nametagName'];
nametagAffiliation = payload['nametagAffiliation'];
nametagRole = payload['nametagRole'];
nametagQrUrl = payload['nametagUrl'];
});
if (result) {
Timer(Duration(seconds: 1), () {
printNametag();
// final qrCode = qrvision.QrCode();
// qrCode.scanRgbaBytes(byteData, image.width, image.height);
CodeResult zxresult =
zx.readBarcode(byteData, width: image.width, height: image.height);
var zxcontent = zxresult.textString;
// if (qrCode.location != null) {
// print('QR code here: ${qrCode.location}');
if (zxcontent != null) {
try {
print('QR Content found!');
print('QR Content: ${zxcontent}');
var qrContent = zxcontent;
if (!isKioskConfigured) {
try {
var clientConfig = jsonDecode(qrContent);
if (clientConfig.containsKey('config_endpoint') &&
clientConfig.containsKey('token')) {
setState(() {
nametagRole = "키오스크 설정 중입니다.";
});
await configureKiosk(
clientConfig['config_endpoint'], clientConfig['token']);
Map<String, String> envVars = Platform.environment;
final SharedPreferences prefs =
await SharedPreferences.getInstance();
var newKioskClient = KioskClient(
envVars['HOME']! + "/ubuntu_kr_qr_kiosk_check_in_db.db",
prefs.getString('host') ?? '',
prefs.getString('apiToken') ?? '',
prefs.getString('jwtKey') ?? '',
prefs.getString('jwtKeyAlgo') ?? '');
setState(() {
isKioskConfigured = true;
nametagRole = "체크인 QR을 스캔하세요.";
kioskClient = newKioskClient;
});
await kioskClient.checkInOnServer(qrContent);
}
} on Exception catch (e) {
print(e);
}
} else {
setState(() {
isProcessingQrCheckin = true;
});
var (result, payload) = kioskClient.checkInLocally(qrContent);
setState(() {
nametagName = payload['nametagName'];
nametagAffiliation = payload['nametagAffiliation'];
nametagRole = payload['nametagRole'];
nametagQrUrl = payload['nametagUrl'];
});
if (result) {
Timer(Duration(seconds: 1), () {
printNametag();
});
await kioskClient.checkInOnServer(qrContent);
}
} catch (e) {
print(e);
}
} catch (e) {
print(e);
}
}
// }
}

void printNametag() async {
Expand Down
88 changes: 88 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,46 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.1"
camera:
dependency: transitive
description:
name: camera
sha256: "3ad71371b8168a4c8012c0b40a53c05afc75d46cc688b0f37b4611a841d47b25"
url: "https://pub.dev"
source: hosted
version: "0.9.8+1"
camera_android:
dependency: transitive
description:
name: camera_android
sha256: "665d62c1f334722c7519ca5d3b94ad68ecaa801691870602da5638a42c1fff67"
url: "https://pub.dev"
source: hosted
version: "0.9.8+3"
camera_avfoundation:
dependency: transitive
description:
name: camera_avfoundation
sha256: "1a416e452b30955b392f4efbf23291d3f2ba3660a85e1628859eb62d2a2bab26"
url: "https://pub.dev"
source: hosted
version: "0.9.13+2"
camera_platform_interface:
dependency: transitive
description:
name: camera_platform_interface
sha256: "60fa0bb62a4f3bf3a7c413e31e4cd01b69c779ccc8e4668904a24581b86c316b"
url: "https://pub.dev"
source: hosted
version: "2.5.1"
camera_web:
dependency: transitive
description:
name: camera_web
sha256: "18cdbee5441e9a6fb129fdd9b68a06d1b8c5236932ba97d5faeaefe80db2e5bd"
url: "https://pub.dev"
source: hosted
version: "0.2.1+6"
characters:
dependency: transitive
description:
Expand Down Expand Up @@ -73,6 +113,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.1.1"
cross_file:
dependency: transitive
description:
name: cross_file
sha256: "0b0036e8cccbfbe0555fd83c1d31a6f30b77a96b598b35a5d36dd41f718695e9"
url: "https://pub.dev"
source: hosted
version: "0.3.3+4"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -158,6 +206,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_beep:
dependency: transitive
description:
name: flutter_beep
sha256: "299bec757177afad07d27126155e0cf3167160ccf2a003645cd71ac014ccd541"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
flutter_gstreamer_player:
dependency: "direct main"
description:
Expand All @@ -174,6 +230,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
sha256: "950e77c2bbe1692bc0874fc7fb491b96a4dc340457f4ea1641443d0a6c1ea360"
url: "https://pub.dev"
source: hosted
version: "2.0.15"
flutter_test:
dependency: "direct dev"
description: flutter
Expand All @@ -184,6 +248,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_zxing:
dependency: "direct main"
description:
name: flutter_zxing
sha256: ff0139937b847472fc8da38b3bb5251cd35489c4999e4722afd4e8484170649b
url: "https://pub.dev"
source: hosted
version: "0.4.0"
http:
dependency: "direct main"
description:
Expand Down Expand Up @@ -376,6 +448,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.3.1"
quiver:
dependency: transitive
description:
name: quiver
sha256: b1c1ac5ce6688d77f65f3375a9abb9319b3cb32486bdc7a1e0fdf004d7ba4e47
url: "https://pub.dev"
source: hosted
version: "3.2.1"
shared_preferences:
dependency: "direct main"
description:
Expand Down Expand Up @@ -469,6 +549,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.1"
stream_transform:
dependency: transitive
description:
name: stream_transform
sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
string_scanner:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies:
sqlite3: ^2.0.0
shared_preferences: ^2.2.0
http: ^1.1.0
flutter_zxing: ^0.4.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 1e116fc

Please sign in to comment.