Skip to content

Commit

Permalink
add: continuous scan barcode
Browse files Browse the repository at this point in the history
  • Loading branch information
liupandeng committed Jun 13, 2022
1 parent 9468b58 commit e987852
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 176 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [3.2.1]

* fix something
* improve something

## [3.2.0]

* Flutter 3.0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.air.ai_barcode

import android.content.Context
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import com.google.zxing.BarcodeFormat
import com.google.zxing.ResultPoint
Expand Down Expand Up @@ -30,11 +29,11 @@ class AndroidScannerView(
* 用于向Flutter发送数据
*/
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
this.eventChannelSink = events;
this.eventChannelSink?.success("onListen");
this.mEventChannelSink = events;
}

override fun onCancel(arguments: Any?) {
this.mEventChannelSink?.endOfStream();
}


Expand All @@ -50,7 +49,7 @@ class AndroidScannerView(

mLastText = result.text

this.channelResult.success(result.text.toString());
this.mEventChannelSink?.success(result.text.toString());
}

override fun possibleResultPoints(resultPoints: MutableList<ResultPoint>?) {
Expand Down Expand Up @@ -87,7 +86,7 @@ class AndroidScannerView(


lateinit var channelResult: MethodChannel.Result;
var eventChannelSink: EventChannel.EventSink? = null;
var mEventChannelSink: EventChannel.EventSink? = null;

init {
mTextView.text = "Scanner view";
Expand Down
2 changes: 0 additions & 2 deletions example/lib/app_barcode_scanner_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ class _AppBarcodeScannerWidgetState extends State<_BarcodeScannerWidget> {
super.initState();

_scannerController = ScannerController(scannerResult: (result) {
_scannerController.stopCameraPreview();

_resultCallback(result);
}, scannerViewCreated: () {
TargetPlatform platform = Theme.of(context).platform;
Expand Down
87 changes: 6 additions & 81 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,14 @@ packages:
path: ".."
relative: true
source: path
version: "3.1.0"
version: "3.2.0"
ai_barcode_platform_interface:
dependency: transitive
description:
name: ai_barcode_platform_interface
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "3.0.0"
ai_barcode_web:
dependency: transitive
description:
name: ai_barcode_web
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "3.0.0"
path: "../../ai_barcode_platform_interface"
relative: true
source: path
version: "3.0.1"
air_design:
dependency: "direct main"
description:
Expand Down Expand Up @@ -85,20 +78,6 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "1.16.0"
crypto:
dependency: transitive
description:
name: crypto
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "3.0.2"
csslib:
dependency: transitive
description:
name: csslib
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.17.2"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -123,25 +102,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
html:
dependency: transitive
description:
name: html
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.15.0"
js:
dependency: transitive
description:
name: js
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.6.4"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -191,20 +151,6 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.1.2"
qr:
dependency: transitive
description:
name: qr
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.1.0"
qr_flutter:
dependency: transitive
description:
name: qr_flutter
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "4.0.0"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -252,27 +198,6 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.4.9"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "1.3.1"
universal_html:
dependency: transitive
description:
name: universal_html
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.0.8"
universal_io:
dependency: transitive
description:
name: universal_io
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.0.4"
vector_math:
dependency: transitive
description:
Expand All @@ -281,5 +206,5 @@ packages:
source: hosted
version: "2.1.2"
sdks:
dart: ">=2.17.0-0 <3.0.0"
dart: ">=2.17.1 <3.0.0"
flutter: ">=2.5.0"
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Demonstrates how to use the ai_barcode plugin.
publish_to: 'none'

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.17.1 <3.0.0"

dependencies:
flutter:
Expand Down
17 changes: 15 additions & 2 deletions lib/src/ai_barcode_widget.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';

import 'package:ai_barcode/src/creator/ai_barcode_mobile_creator_plugin.dart';
Expand Down Expand Up @@ -40,7 +41,7 @@ class PlatformAiBarcodeScannerWidget extends StatefulWidget {
/// _PlatformScannerWidgetState
class _PlatformScannerWidgetState
extends State<PlatformAiBarcodeScannerWidget> {
// StreamSubscription _streamSubscription;
StreamSubscription? _streamSubscription;

@override
void initState() {
Expand All @@ -52,21 +53,31 @@ class _PlatformScannerWidgetState
_widgetCreatedListener() {
if (widget._platformScannerController._scannerViewCreated != null) {
widget._platformScannerController._scannerViewCreated!();
_streamSubscription = AiBarcodeScannerPlatform.instance
.receiveBarcodeResult()
.listen((event) {
_receiveBarcodeResultCallback("$event");
});
}
}

void _receiveBarcodeResultCallback(String result) {
widget._platformScannerController._scannerResult(result);
}

///
/// Web result callback
void _webResultCallback(String result) {
//if (widget._platformScannerController._scannerResult != null) {
//callback
widget._platformScannerController._scannerResult(result);
// widget._platformScannerController._scannerResult(result);
//}
}

@override
void dispose() {
super.dispose();
_streamSubscription?.cancel();
//Release
AiBarcodeScannerPlatform.instance.removeListener(_widgetCreatedListener);
AiBarcodeScannerPlatform.instance.removeResultCallback(_webResultCallback);
Expand Down Expand Up @@ -109,6 +120,7 @@ class ScannerController {
Function()? get scannerViewCreated => _scannerViewCreated;

bool get isStartCamera => AiBarcodeScannerPlatform.instance.isStartCamera;

bool get isStartCameraPreview =>
AiBarcodeScannerPlatform.instance.isStartCameraPreview;

Expand Down Expand Up @@ -177,6 +189,7 @@ class PlatformAiBarcodeCreatorWidget extends StatefulWidget {
_initialValue = initialValue;
_unsupportedDescription = unsupportedDescription;
}

@override
State<StatefulWidget> createState() {
return _PlatformAiBarcodeCreatorState();
Expand Down
85 changes: 5 additions & 80 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@ packages:
ai_barcode_platform_interface:
dependency: "direct main"
description:
name: ai_barcode_platform_interface
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "3.0.0"
ai_barcode_web:
dependency: "direct main"
description:
name: ai_barcode_web
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "3.0.0"
path: "../ai_barcode_platform_interface"
relative: true
source: path
version: "3.0.1"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -57,20 +50,6 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "1.16.0"
crypto:
dependency: transitive
description:
name: crypto
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "3.0.2"
csslib:
dependency: transitive
description:
name: csslib
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.17.2"
fake_async:
dependency: transitive
description:
Expand All @@ -95,25 +74,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
html:
dependency: transitive
description:
name: html
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.15.0"
js:
dependency: transitive
description:
name: js
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.6.4"
lints:
dependency: transitive
description:
Expand Down Expand Up @@ -149,20 +109,6 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "1.8.1"
qr:
dependency: transitive
description:
name: qr
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.1.0"
qr_flutter:
dependency: transitive
description:
name: qr_flutter
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "4.0.0"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -210,27 +156,6 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.4.9"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "1.3.1"
universal_html:
dependency: transitive
description:
name: universal_html
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.0.8"
universal_io:
dependency: transitive
description:
name: universal_io
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.0.4"
vector_math:
dependency: transitive
description:
Expand All @@ -240,4 +165,4 @@ packages:
version: "2.1.2"
sdks:
dart: ">=2.17.0-206.0.dev <3.0.0"
flutter: ">=2.0.0"
flutter: ">=2.5.0"
Loading

0 comments on commit e987852

Please sign in to comment.