|
|
|
@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_qr_reader/flutter_qr_reader.dart';
|
|
|
|
|
import 'package:flutter_qr_reader/qrcode_reader_view.dart';
|
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
|
import 'package:just_audio/just_audio.dart';
|
|
|
|
|
|
|
|
|
|
import 'package:recook/base/base_store_state.dart';
|
|
|
|
|
import 'package:recook/constants/api.dart';
|
|
|
|
@ -20,17 +21,16 @@ import 'package:recook/utils/text_utils.dart';
|
|
|
|
|
// import 'package:flutter_audio_player/flutter_audio_player.dart';
|
|
|
|
|
|
|
|
|
|
class BarcodeScanPage extends StatefulWidget {
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<BarcodeScanPage> createState() {
|
|
|
|
|
return _BarcodeScanPageState();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _BarcodeScanPageState extends BaseStoreState<BarcodeScanPage> {
|
|
|
|
|
String barcode = "";
|
|
|
|
|
GlobalKey<QrcodeReaderViewState> _key = GlobalKey();
|
|
|
|
|
final player = AudioPlayer();
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
@ -46,12 +46,13 @@ class _BarcodeScanPageState extends BaseStoreState<BarcodeScanPage> {
|
|
|
|
|
QrcodeReaderView(
|
|
|
|
|
key: _key,
|
|
|
|
|
helpWidget: Text("请将条形码置于方框中间"),
|
|
|
|
|
onEdit: (){
|
|
|
|
|
onEdit: () {
|
|
|
|
|
AppRouter.pushAndReplaced(context, RouteName.BARCODE_INPUT);
|
|
|
|
|
},
|
|
|
|
|
onSelectImage: () async {
|
|
|
|
|
_key.currentState.stopScan();
|
|
|
|
|
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
|
|
|
|
|
var image =
|
|
|
|
|
await ImagePicker.pickImage(source: ImageSource.gallery);
|
|
|
|
|
if (image == null) {
|
|
|
|
|
_key.currentState.startScan();
|
|
|
|
|
return;
|
|
|
|
@ -63,11 +64,11 @@ class _BarcodeScanPageState extends BaseStoreState<BarcodeScanPage> {
|
|
|
|
|
}
|
|
|
|
|
File imageFile = cropFile;
|
|
|
|
|
final rest = await FlutterQrReader.imgScan(imageFile);
|
|
|
|
|
if (TextUtils.isEmpty(rest)){
|
|
|
|
|
showError("图片识别失败...").then((v){
|
|
|
|
|
if (TextUtils.isEmpty(rest)) {
|
|
|
|
|
showError("图片识别失败...").then((v) {
|
|
|
|
|
_key.currentState.startScan();
|
|
|
|
|
});
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
onScan(rest, image: imageFile);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
@ -78,60 +79,57 @@ class _BarcodeScanPageState extends BaseStoreState<BarcodeScanPage> {
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Positioned(
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: lineColor,
|
|
|
|
|
borderRadius: BorderRadius.circular(0.5),
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: lineColor,
|
|
|
|
|
borderRadius: BorderRadius.circular(0.5),
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: lineColor,
|
|
|
|
|
offset: Offset(0, 1),
|
|
|
|
|
blurRadius: 5,
|
|
|
|
|
spreadRadius: 1.0
|
|
|
|
|
),
|
|
|
|
|
BoxShadow(
|
|
|
|
|
spreadRadius: 1.0),
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: lineColor,
|
|
|
|
|
offset: Offset(0, -1),
|
|
|
|
|
blurRadius: 5,
|
|
|
|
|
spreadRadius: 1.0
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
width: width*0.8,
|
|
|
|
|
height: 1.7,
|
|
|
|
|
spreadRadius: 1.0),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
width: width * 0.8,
|
|
|
|
|
height: 1.7,
|
|
|
|
|
),
|
|
|
|
|
)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future onScan(String data, {File image}) async{
|
|
|
|
|
if (!TextUtils.isEmpty(data)){
|
|
|
|
|
Future onScan(String data, {File image}) async {
|
|
|
|
|
if (!TextUtils.isEmpty(data)) {
|
|
|
|
|
_playSound();
|
|
|
|
|
_key.currentState.stopScan();
|
|
|
|
|
Future.delayed(Duration(milliseconds: 500 ), (){
|
|
|
|
|
_getGoodsWithCode(data, (goodsId){
|
|
|
|
|
AppRouter.pushAndReplaced(globalContext, RouteName.COMMODITY_PAGE, arguments: CommodityDetailPage.setArguments(int.parse(goodsId)));
|
|
|
|
|
Future.delayed(Duration(milliseconds: 500), () {
|
|
|
|
|
_getGoodsWithCode(data, (goodsId) {
|
|
|
|
|
AppRouter.pushAndReplaced(globalContext, RouteName.COMMODITY_PAGE,
|
|
|
|
|
arguments: CommodityDetailPage.setArguments(int.parse(goodsId)));
|
|
|
|
|
return;
|
|
|
|
|
}, image: image);
|
|
|
|
|
});
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
_key.currentState.startScan();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_playSound() async {
|
|
|
|
|
// AudioPlayer.addSound("assets/sound/recook_scan.mp3");
|
|
|
|
|
_playSound() async {
|
|
|
|
|
player.setAsset('assets/sound/recook_scan.mp3');
|
|
|
|
|
player.play();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_getGoodsWithCode(String code, Function callBack, {File image}) async {
|
|
|
|
|
|
|
|
|
|
ResultData resultData = await HttpManager.post(GoodsApi.goods_code_search, {
|
|
|
|
|
"code":code,
|
|
|
|
|
"code": code,
|
|
|
|
|
});
|
|
|
|
|
if (!resultData.result) {
|
|
|
|
|
pushToFailPage(code, resultData.msg, image);
|
|
|
|
@ -150,11 +148,13 @@ class _BarcodeScanPageState extends BaseStoreState<BarcodeScanPage> {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pushToFailPage(String code, String message, File image){
|
|
|
|
|
pushToFailPage(String code, String message, File image) {
|
|
|
|
|
if (image != null) {
|
|
|
|
|
AppRouter.pushAndReplaced(context, RouteName.BARCODE_PHOTOSFAIL, arguments: PhotosFailBarcodePage.setArguments(code, message, image));
|
|
|
|
|
}else{
|
|
|
|
|
AppRouter.pushAndReplaced(context, RouteName.BARCODE_FAIL, arguments: FailBarcodePage.setArguments(code, message));
|
|
|
|
|
AppRouter.pushAndReplaced(context, RouteName.BARCODE_PHOTOSFAIL,
|
|
|
|
|
arguments: PhotosFailBarcodePage.setArguments(code, message, image));
|
|
|
|
|
} else {
|
|
|
|
|
AppRouter.pushAndReplaced(context, RouteName.BARCODE_FAIL,
|
|
|
|
|
arguments: FailBarcodePage.setArguments(code, message));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -162,5 +162,4 @@ class _BarcodeScanPageState extends BaseStoreState<BarcodeScanPage> {
|
|
|
|
|
void dispose() {
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|