Skip to content

Commit 704118f

Browse files
Merge pull request #22 from CodingWithTashi/revert-21-main
Revert "Removed the inline script in barcode.html file and added two properties to set qrbox width and height in web apps"
2 parents 63f94a5 + 64c03fb commit 704118f

File tree

7 files changed

+47
-90
lines changed

7 files changed

+47
-90
lines changed

lib/assets/barcode.html

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,50 @@
2020
<body>
2121
<!-- Div to show the scanner -->
2222
<div id="reader" ></div>
23-
<script src="reader.js"></script>
23+
<script>
24+
//refer doc here https://github.com/mebjas/html5-qrcode
25+
const html5QrCode = new Html5Qrcode("reader");
26+
console.log("Starting SCANNING CODE");
27+
const qrCodeSuccessCallback = (decodedText, decodedResult) => {
28+
html5QrCode.stop();
29+
/* handle success for web */
30+
window.parent.postMessage(decodedText, "*");
31+
32+
/* handle success for window */
33+
if (window.chrome.webview != "undefined") {
34+
var param = {
35+
"methodName": "successCallback",
36+
"data": decodedText
37+
}
38+
window.chrome.webview.postMessage(param);
39+
}
40+
41+
};
42+
const config = {
43+
fps: 10,
44+
qrbox: {
45+
width: 280,
46+
height: 120,
47+
aspectRatio: 1.7777778
48+
}
49+
};
50+
51+
// If you want to prefer back camera
52+
html5QrCode.start({
53+
facingMode: "environment"
54+
}, config, qrCodeSuccessCallback);
55+
//html5QrCode.start({ facingMode: "user" }, config, qrCodeSuccessCallback);
56+
57+
//Window event listener
58+
if (window.chrome.webview != undefined) {
59+
window.chrome.webview.addEventListener('message', function(e) {
60+
let data = JSON.parse(JSON.stringify(e.data));
61+
if (data.event === "close") {
62+
html5QrCode.stop();
63+
}
64+
65+
});
66+
}
67+
</script>
2468
</body>
2569
</html>

lib/assets/reader.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

lib/screens/io_device.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ class BarcodeScanner extends StatelessWidget {
1414
final Function(String) onScanned;
1515
final String? appBarTitle;
1616
final bool? centerTitle;
17-
/// Properties only added to standardize the implementation of the BarcodeScanner class
18-
final int scanWidth;
19-
final int scanHeight;
20-
2117
const BarcodeScanner({
2218
Key? key,
2319
required this.lineColor,
@@ -27,8 +23,6 @@ class BarcodeScanner extends StatelessWidget {
2723
required this.onScanned,
2824
this.appBarTitle,
2925
this.centerTitle,
30-
this.scanWidth = 0,
31-
this.scanHeight = 0
3226
}) : super(key: key);
3327

3428
@override

lib/screens/unsupported.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ class BarcodeScanner extends StatelessWidget {
99
final Function(String) onScanned;
1010
final String? appBarTitle;
1111
final bool? centerTitle;
12-
/// Properties only added to standardize the implementation of the BarcodeScanner class
13-
final int scanWidth;
14-
final int scanHeight;
15-
1612
const BarcodeScanner(
1713
{Key? key,
1814
this.lineColor = "#ff6666",
@@ -21,9 +17,7 @@ class BarcodeScanner extends StatelessWidget {
2117
this.scanType = ScanType.barcode,
2218
required this.onScanned,
2319
this.appBarTitle,
24-
this.centerTitle,
25-
this.scanWidth = 0,
26-
this.scanHeight= 0})
20+
this.centerTitle})
2721
: super(key: key);
2822

2923
@override

lib/screens/web.dart

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// ignore: avoid_web_libraries_in_flutter
22
import 'dart:html' as html;
33
import 'dart:ui' as ui;
4-
import 'dart:js' as js;
54

65
import 'package:flutter/material.dart';
76
import 'package:simple_barcode_scanner/constant.dart';
@@ -16,8 +15,6 @@ class BarcodeScanner extends StatelessWidget {
1615
final Function(String) onScanned;
1716
final String? appBarTitle;
1817
final bool? centerTitle;
19-
final int scanWidth;
20-
final int scanHeight;
2118

2219
const BarcodeScanner({
2320
Key? key,
@@ -28,8 +25,6 @@ class BarcodeScanner extends StatelessWidget {
2825
required this.onScanned,
2926
this.appBarTitle,
3027
this.centerTitle,
31-
this.scanWidth = 288,
32-
this.scanHeight = 120
3328
}) : super(key: key);
3429

3530
@override
@@ -41,15 +36,8 @@ class BarcodeScanner extends StatelessWidget {
4136
..src = PackageConstant.barcodeFileWebPath
4237
..style.border = 'none'
4338
..onLoad.listen((event) async {
44-
html.window.onMessage.listen((event) {
45-
/// Create reader setting qrBox width and height
46-
html.CustomEvent event = new html.CustomEvent("reader", detail : {
47-
"qrBoxWidth": scanWidth,
48-
"qrBoxHeight": scanHeight
49-
});
50-
html.window.document.dispatchEvent(event);
51-
5239
/// Barcode listener on success barcode scanned
40+
html.window.onMessage.listen((event) {
5341
/// If barcode is null then assign scanned barcode
5442
/// and close the screen otherwise keep scanning
5543
if (barcodeNumber == null) {

lib/simple_barcode_scanner.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ class SimpleBarcodeScannerPage extends StatelessWidget {
2525
///center Title
2626
final bool? centerTitle;
2727

28-
/// Only for web apps, set qrBox width and height
29-
final int scanWidth;
30-
final int scanHeight;
31-
3228
/// appBatTitle and centerTitle support in web and window only
3329
/// Remaining field support in only mobile devices
3430
const SimpleBarcodeScannerPage({
@@ -39,8 +35,6 @@ class SimpleBarcodeScannerPage extends StatelessWidget {
3935
this.scanType = ScanType.barcode,
4036
this.appBarTitle,
4137
this.centerTitle,
42-
this.scanWidth = 280,
43-
this.scanHeight = 120
4438
}) : super(key: key);
4539

4640
@override

pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ flutter:
3939
assets:
4040
- packages/simple_barcode_scanner/assets/barcode.html
4141
- packages/simple_barcode_scanner/assets/html5-qrcode.min.js
42-
- packages/simple_barcode_scanner/assets/reader.js
4342
#
4443
# For details regarding assets in packages, see
4544
# https://flutter.dev/assets-and-images/#from-packages

0 commit comments

Comments
 (0)