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. 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 ## Demo Screenshots
<pre> <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; <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> </pre>
@ -34,6 +34,7 @@ A barcode and QR code scanner based on [ZXing C++](https://github.com/nu-book/zx
| | DataBar Expanded | | | DataBar Expanded |
## Features ## Features
- Scan barcode from camera stream, image path or url - Scan barcode from camera stream, image path or url
- Scan multiple barcodes from camera stream, image path or url - Scan multiple barcodes from camera stream, image path or url
- Create barcode from text - 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 - Flashlight and pinch to zoom support
## Todo ## Todo
- Write tests - Write tests
## Getting Started ## Getting Started
### To read barcode:
### To read barcode
```dart ```dart
import 'package:flutter_zxing/flutter_zxing.dart'; import 'package:flutter_zxing/flutter_zxing.dart';
@ -62,31 +66,34 @@ Widget build(BuildContext context) {
// Or use flutter_zxing plugin methods // Or use flutter_zxing plugin methods
// To read barcode from camera image directly // To read barcode from camera image directly
await startCameraProcessing(); // Call this in initState await zx.startCameraProcessing(); // Call this in initState
cameraController?.startImageStream((image) async { cameraController?.startImageStream((image) async {
CodeResult result = await processCameraImage(image); Code result = await zx.processCameraImage(image);
if (result.isValidBool) { if (result.isValid) {
debugPrint(result.textString); debugPrint(result.text);
} }
return null; return null;
}); });
stopCameraProcessing(); // Call this in dispose
zx.stopCameraProcessing(); // Call this in dispose
// To read barcode from XFile, String, url or Uint8List bytes // To read barcode from XFile, String, url or Uint8List bytes
XFile xFile = XFile('Your image path'); XFile xFile = XFile('Your image path');
CodeResult? resultFromXFile = await readBarcodeImagePath(xFile); Code? resultFromXFile = await zx.readBarcodeImagePath(xFile);
String path = 'Your local image path'; String path = 'Your local image path';
CodeResult? resultFromPath = await readBarcodeImagePathString(path); Code? resultFromPath = await zx.readBarcodeImagePathString(path);
String url = 'Your remote image url'; String url = 'Your remote image url';
CodeResult? resultFromUrl = await readBarcodeImageUrl(url); Code? resultFromUrl = await zx.readBarcodeImageUrl(url);
Uint8List bytes = Uint8List.fromList(yourImageBytes); Uint8List bytes = Uint8List.fromList(yourImageBytes);
CodeResult? resultFromBytes = await readBarcode(bytes); Code? resultFromBytes = await zx.readBarcode(bytes);
``` ```
### To create barcode: ### To create barcode
```dart ```dart
import 'package:flutter_zxing/flutter_zxing.dart'; import 'package:flutter_zxing/flutter_zxing.dart';
import 'dart:typed_data'; import 'dart:typed_data';
@ -108,7 +115,7 @@ Widget build(BuildContext context) {
); );
// Or use FlutterZxing to create barcode directly // Or use FlutterZxing to create barcode directly
final result = encodeBarcode( final result = zx.encodeBarcode(
'Text to encode', 'Text to encode',
format: Format.QRCode, format: Format.QRCode,
width: 300, width: 300,
@ -116,7 +123,7 @@ final result = encodeBarcode(
margin: 10, margin: 10,
eccLevel: 0, eccLevel: 0,
); );
if (result.isValidBool) { if (result.isValid) {
final img = imglib.Image.fromBytes(width, height, result.bytes); final img = imglib.Image.fromBytes(width, height, result.bytes);
final encodedBytes = Uint8List.fromList(imglib.encodeJpg(img)); final encodedBytes = Uint8List.fromList(imglib.encodeJpg(img));
// use encodedBytes as you wish // use encodedBytes as you wish

2
zxscanner/lib/main.dart

@ -18,7 +18,7 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
await initializePrefs(); await initializePrefs();
await DbService.instance.initializeApp(); await DbService.instance.initializeApp();
setZxingLogEnabled(kDebugMode); zx.setLogEnabled(kDebugMode);
runApp(const MyApp()); 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'; import 'package:hive_flutter/hive_flutter.dart';
part 'code.g.dart'; part 'code.g.dart';
@ -7,10 +7,10 @@ part 'code.g.dart';
class Code extends HiveObject { class Code extends HiveObject {
Code(); Code();
Code.fromCodeResult(CodeResult result) { Code.fromCodeResult(zxing.Code result) {
isValid = result.isValidBool; isValid = result.isValid;
format = result.format; format = result.format;
text = result.textString; text = result.text;
} }
@HiveField(0) @HiveField(0)
bool? isValid; bool? isValid;
@ -21,5 +21,5 @@ class Code extends HiveObject {
@HiveField(2) @HiveField(2)
String? text; 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 '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'; import 'package:hive_flutter/hive_flutter.dart';
part 'encode.g.dart'; part 'encode.g.dart';
@ -9,10 +9,10 @@ part 'encode.g.dart';
class Encode extends HiveObject { class Encode extends HiveObject {
Encode(); Encode();
Encode.fromEncodeResult(EncodeResult result, Uint8List? bytes) { Encode.fromEncodeResult(zxing.Encode result, Uint8List? bytes) {
isValid = result.isValidBool; isValid = result.isValid;
format = result.format; format = result.format;
text = result.textString; text = result.text;
data = bytes; data = bytes;
length = result.length; length = result.length;
} }
@ -31,5 +31,5 @@ class Encode extends HiveObject {
@HiveField(4) @HiveField(4)
int? length; 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 'package:share_plus/share_plus.dart';
import '../configs/constants.dart'; import '../configs/constants.dart';
import '../models/encode.dart'; import '../models/encode.dart' as model;
import '../utils/db_service.dart'; import '../utils/db_service.dart';
import '../utils/extensions.dart'; import '../utils/extensions.dart';
import '../widgets/common_widgets.dart'; import '../widgets/common_widgets.dart';
@ -28,7 +28,7 @@ class _CreatorPageState extends State<CreatorPage> {
bool isAndroid() => Theme.of(context).platform == TargetPlatform.android; bool isAndroid() => Theme.of(context).platform == TargetPlatform.android;
// Write result // Write result
Encode? encode; model.Encode? encode;
@override @override
void initState() { void initState() {
@ -54,9 +54,9 @@ class _CreatorPageState extends State<CreatorPage> {
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
WriterWidget( WriterWidget(
onSuccess: (EncodeResult result, Uint8List? bytes) { onSuccess: (Encode result, Uint8List? bytes) {
setState(() { setState(() {
encode = Encode.fromEncodeResult(result, bytes); encode = model.Encode.fromEncodeResult(result, bytes);
}); });
}, },
onError: (String error) { 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:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:image_picker/image_picker.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/db_service.dart';
import '../utils/extensions.dart'; import '../utils/extensions.dart';
@ -26,7 +26,7 @@ class _ScannerPageState extends State<ScannerPage> {
title: const Text('Scanner'), title: const Text('Scanner'),
), ),
body: ReaderWidget( body: ReaderWidget(
onScan: (CodeResult result) async { onScan: (Code result) async {
addCode(result); addCode(result);
}, },
), ),
@ -51,8 +51,8 @@ class _ScannerPageState extends State<ScannerPage> {
} }
Future<void> readCodeFromImage(XFile file) async { Future<void> readCodeFromImage(XFile file) async {
final CodeResult? result = await readBarcodeImagePath(file); final Code? result = await zx.readBarcodeImagePath(file);
if (result != null && result.isValidBool) { if (result != null && result.isValid) {
addCode(result); addCode(result);
} else { } else {
if (!mounted) { if (!mounted) {
@ -62,8 +62,8 @@ class _ScannerPageState extends State<ScannerPage> {
} }
} }
void addCode(CodeResult result) { void addCode(Code result) {
final Code code = Code.fromCodeResult(result); final model.Code code = model.Code.fromCodeResult(result);
DbService.instance.addCode(code); DbService.instance.addCode(code);
context.showToast('Code added:\n${code.text ?? ''}'); context.showToast('Code added:\n${code.text ?? ''}');
} }

10
zxscanner/pubspec.lock

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

2
zxscanner/pubspec.yaml

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

Loading…
Cancel
Save