Browse Source

updated readme

pull/62/head
Khoren Markosyan 2 years ago
parent
commit
22683e4f7e
  1. 35
      README.md
  2. 2
      zxscanner/lib/main.dart
  3. 10
      zxscanner/lib/models/code.dart
  4. 10
      zxscanner/lib/models/encode.dart
  5. 8
      zxscanner/lib/pages/creator_page.dart
  6. 12
      zxscanner/lib/pages/scanner_page.dart
  7. 10
      zxscanner/pubspec.lock
  8. 2
      zxscanner/pubspec.yaml

35
README.md

@ -16,8 +16,8 @@
A barcode and QR code scanner based on [ZXing C++](https://github.com/nu-book/zxing-cpp) library natively in Flutter with Dart FFI.
## Demo Screenshots
<pre>
<img alt="01_scanner_screen" src="https://user-images.githubusercontent.com/11523360/174789425-b33861aa-dbe5-49c1-a84a-a02b514a5e0f.png" width="240">&nbsp; <img alt="02_creator_screen" src="https://user-images.githubusercontent.com/11523360/174789816-a2a4ab74-f5ef-41a1-98f3-e514447dff5a.png" width="240">&nbsp;
</pre>
@ -34,6 +34,7 @@ A barcode and QR code scanner based on [ZXing C++](https://github.com/nu-book/zx
| | DataBar Expanded |
## Features
- Scan barcode from camera stream, image path or url
- Scan multiple barcodes from camera stream, image path or url
- Create barcode from text
@ -41,10 +42,13 @@ A barcode and QR code scanner based on [ZXing C++](https://github.com/nu-book/zx
- Flashlight and pinch to zoom support
## Todo
- Write tests
## Getting Started
### To read barcode:
### To read barcode
```dart
import 'package:flutter_zxing/flutter_zxing.dart';
@ -62,31 +66,34 @@ Widget build(BuildContext context) {
// Or use flutter_zxing plugin methods
// To read barcode from camera image directly
await startCameraProcessing(); // Call this in initState
await zx.startCameraProcessing(); // Call this in initState
cameraController?.startImageStream((image) async {
CodeResult result = await processCameraImage(image);
if (result.isValidBool) {
debugPrint(result.textString);
Code result = await zx.processCameraImage(image);
if (result.isValid) {
debugPrint(result.text);
}
return null;
});
stopCameraProcessing(); // Call this in dispose
zx.stopCameraProcessing(); // Call this in dispose
// To read barcode from XFile, String, url or Uint8List bytes
XFile xFile = XFile('Your image path');
CodeResult? resultFromXFile = await readBarcodeImagePath(xFile);
Code? resultFromXFile = await zx.readBarcodeImagePath(xFile);
String path = 'Your local image path';
CodeResult? resultFromPath = await readBarcodeImagePathString(path);
Code? resultFromPath = await zx.readBarcodeImagePathString(path);
String url = 'Your remote image url';
CodeResult? resultFromUrl = await readBarcodeImageUrl(url);
Code? resultFromUrl = await zx.readBarcodeImageUrl(url);
Uint8List bytes = Uint8List.fromList(yourImageBytes);
CodeResult? resultFromBytes = await readBarcode(bytes);
Code? resultFromBytes = await zx.readBarcode(bytes);
```
### To create barcode:
### To create barcode
```dart
import 'package:flutter_zxing/flutter_zxing.dart';
import 'dart:typed_data';
@ -108,7 +115,7 @@ Widget build(BuildContext context) {
);
// Or use FlutterZxing to create barcode directly
final result = encodeBarcode(
final result = zx.encodeBarcode(
'Text to encode',
format: Format.QRCode,
width: 300,
@ -116,7 +123,7 @@ final result = encodeBarcode(
margin: 10,
eccLevel: 0,
);
if (result.isValidBool) {
if (result.isValid) {
final img = imglib.Image.fromBytes(width, height, result.bytes);
final encodedBytes = Uint8List.fromList(imglib.encodeJpg(img));
// use encodedBytes as you wish

2
zxscanner/lib/main.dart

@ -18,7 +18,7 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();
await initializePrefs();
await DbService.instance.initializeApp();
setZxingLogEnabled(kDebugMode);
zx.setLogEnabled(kDebugMode);
runApp(const MyApp());
}

10
zxscanner/lib/models/code.dart

@ -1,4 +1,4 @@
import 'package:flutter_zxing/flutter_zxing.dart';
import 'package:flutter_zxing/flutter_zxing.dart' as zxing;
import 'package:hive_flutter/hive_flutter.dart';
part 'code.g.dart';
@ -7,10 +7,10 @@ part 'code.g.dart';
class Code extends HiveObject {
Code();
Code.fromCodeResult(CodeResult result) {
isValid = result.isValidBool;
Code.fromCodeResult(zxing.Code result) {
isValid = result.isValid;
format = result.format;
text = result.textString;
text = result.text;
}
@HiveField(0)
bool? isValid;
@ -21,5 +21,5 @@ class Code extends HiveObject {
@HiveField(2)
String? text;
String get formatName => barcodeFormatName(format ?? 0);
String get formatName => zxing.zx.barcodeFormatName(format ?? 0);
}

10
zxscanner/lib/models/encode.dart

@ -1,6 +1,6 @@
import 'dart:typed_data';
import 'package:flutter_zxing/flutter_zxing.dart';
import 'package:flutter_zxing/flutter_zxing.dart' as zxing;
import 'package:hive_flutter/hive_flutter.dart';
part 'encode.g.dart';
@ -9,10 +9,10 @@ part 'encode.g.dart';
class Encode extends HiveObject {
Encode();
Encode.fromEncodeResult(EncodeResult result, Uint8List? bytes) {
isValid = result.isValidBool;
Encode.fromEncodeResult(zxing.Encode result, Uint8List? bytes) {
isValid = result.isValid;
format = result.format;
text = result.textString;
text = result.text;
data = bytes;
length = result.length;
}
@ -31,5 +31,5 @@ class Encode extends HiveObject {
@HiveField(4)
int? length;
String get formatName => barcodeFormatName(format ?? 0);
String get formatName => zxing.zx.barcodeFormatName(format ?? 0);
}

8
zxscanner/lib/pages/creator_page.dart

@ -7,7 +7,7 @@ import 'package:path_provider/path_provider.dart';
import 'package:share_plus/share_plus.dart';
import '../configs/constants.dart';
import '../models/encode.dart';
import '../models/encode.dart' as model;
import '../utils/db_service.dart';
import '../utils/extensions.dart';
import '../widgets/common_widgets.dart';
@ -28,7 +28,7 @@ class _CreatorPageState extends State<CreatorPage> {
bool isAndroid() => Theme.of(context).platform == TargetPlatform.android;
// Write result
Encode? encode;
model.Encode? encode;
@override
void initState() {
@ -54,9 +54,9 @@ class _CreatorPageState extends State<CreatorPage> {
child: Column(
children: <Widget>[
WriterWidget(
onSuccess: (EncodeResult result, Uint8List? bytes) {
onSuccess: (Encode result, Uint8List? bytes) {
setState(() {
encode = Encode.fromEncodeResult(result, bytes);
encode = model.Encode.fromEncodeResult(result, bytes);
});
},
onError: (String error) {

12
zxscanner/lib/pages/scanner_page.dart

@ -3,7 +3,7 @@ import 'package:flutter_zxing/flutter_zxing.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:image_picker/image_picker.dart';
import '../models/models.dart';
import '../models/models.dart' as model;
import '../utils/db_service.dart';
import '../utils/extensions.dart';
@ -26,7 +26,7 @@ class _ScannerPageState extends State<ScannerPage> {
title: const Text('Scanner'),
),
body: ReaderWidget(
onScan: (CodeResult result) async {
onScan: (Code result) async {
addCode(result);
},
),
@ -51,8 +51,8 @@ class _ScannerPageState extends State<ScannerPage> {
}
Future<void> readCodeFromImage(XFile file) async {
final CodeResult? result = await readBarcodeImagePath(file);
if (result != null && result.isValidBool) {
final Code? result = await zx.readBarcodeImagePath(file);
if (result != null && result.isValid) {
addCode(result);
} else {
if (!mounted) {
@ -62,8 +62,8 @@ class _ScannerPageState extends State<ScannerPage> {
}
}
void addCode(CodeResult result) {
final Code code = Code.fromCodeResult(result);
void addCode(Code result) {
final model.Code code = model.Code.fromCodeResult(result);
DbService.instance.addCode(code);
context.showToast('Code added:\n${code.text ?? ''}');
}

10
zxscanner/pubspec.lock

@ -77,7 +77,7 @@ packages:
name: build_runner
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.2"
version: "2.3.3"
build_runner_core:
dependency: transitive
description:
@ -321,7 +321,7 @@ packages:
name: flutter_zxing
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.5"
version: "0.9.0"
font_awesome_flutter:
dependency: "direct main"
description:
@ -426,7 +426,7 @@ packages:
name: image_picker_android
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.5+3"
version: "0.8.5+4"
image_picker_for_web:
dependency: transitive
description:
@ -440,7 +440,7 @@ packages:
name: image_picker_ios
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.6+1"
version: "0.8.6+2"
image_picker_platform_interface:
dependency: transitive
description:
@ -928,7 +928,7 @@ packages:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.2"
version: "3.1.3"
xdg_directories:
dependency: transitive
description:

2
zxscanner/pubspec.yaml

@ -36,7 +36,7 @@ flutter_intl:
enabled: true
dev_dependencies:
build_runner: ^2.2.1
build_runner: ^2.3.3
# espresso: ^0.2.0+2
flutter_lints: ^2.0.1
flutter_native_splash: ^2.2.16 # flutter pub run flutter_native_splash:create

Loading…
Cancel
Save