添加 扫码完成页面

master
zhangmeng 4 years ago
parent 31468312c9
commit 322b2724e0

@ -1,5 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:recook/base/base_store_state.dart';
import 'package:recook/constants/api.dart';
@ -7,6 +8,7 @@ import 'package:recook/constants/header.dart';
import 'package:recook/constants/styles.dart';
import 'package:recook/manager/http_manager.dart';
import 'package:recook/models/base_model.dart';
import 'package:recook/pages/home/barcode/qr_scaner_result_page.dart';
import 'package:recook/pages/home/classify/commodity_detail_page.dart';
import 'package:recook/widgets/custom_app_bar.dart';
import 'package:recook/widgets/custom_image_button.dart';
@ -19,37 +21,33 @@ class InputBarcodePage extends StatefulWidget {
}
class _InputBarcodePageState extends BaseStoreState<InputBarcodePage> {
final _textEditcontroller = TextEditingController();
@override
void initState() {
void initState() {
super.initState();
}
@override
Widget buildContext(BuildContext context, {store}) {
return GestureDetector(
onTap: (){
onTap: () {
FocusScope.of(context).requestFocus(FocusNode());
},
child: Scaffold(
appBar: CustomAppBar(
title: "",
themeData: AppThemes.themeDataGrey.appBarTheme,
appBackground: Colors.white,
elevation: 0,
),
body: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: _bodyWidget(),
)
),
appBar: CustomAppBar(
title: "",
themeData: AppThemes.themeDataGrey.appBarTheme,
appBackground: Colors.white,
elevation: 0,
),
body: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: _bodyWidget(),
)),
);
}
}
_bodyWidget(){
_bodyWidget() {
double width = MediaQuery.of(context).size.width;
Color buttonColor = Color(0xffE98787);
return Container(
@ -60,24 +58,38 @@ class _InputBarcodePageState extends BaseStoreState<InputBarcodePage> {
alignment: Alignment.centerLeft,
width: width,
padding: EdgeInsets.only(left: 30, top: 20),
child: Text("填写商品条码", style: TextStyle(color: Colors.black, fontSize: ScreenAdapterUtils.setSp(22)),),
child: Text(
"填写商品条码",
style: TextStyle(
color: Colors.black, fontSize: ScreenAdapterUtils.setSp(22)),
),
),
inputWidget(),
Container(
padding: EdgeInsets.only(left: 30, right: 30, top: 30,),
padding: EdgeInsets.only(
left: 30,
right: 30,
top: 30,
),
child: CustomImageButton(
height: ScreenAdapterUtils.setHeight(36),
backgroundColor: AppColor.themeColor,
title: "确认",
color: Colors.white,
fontSize: 16,
onPressed: TextUtils.isEmpty(_textEditcontroller.text)?null:(){
_getGoodsWithCode(_textEditcontroller.text);
},
onPressed: TextUtils.isEmpty(_textEditcontroller.text)
? null
: () {
_getGoodsWithCode(_textEditcontroller.text);
},
),
),
Container(
padding: EdgeInsets.only(left: 30, right: 30, top: 20,),
padding: EdgeInsets.only(
left: 30,
right: 30,
top: 20,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
@ -90,12 +102,15 @@ class _InputBarcodePageState extends BaseStoreState<InputBarcodePage> {
color: buttonColor,
),
fontSize: 16,
onPressed: (){
AppRouter.pushAndReplaced(context, RouteName.BARCODE_SCAN);
onPressed: () {
AppRouter.pushAndReplaced(
context, RouteName.BARCODE_SCAN);
},
),
),
Container(width: 30,),
Container(
width: 30,
),
Expanded(
child: CustomImageButton(
height: ScreenAdapterUtils.setHeight(36),
@ -105,7 +120,7 @@ class _InputBarcodePageState extends BaseStoreState<InputBarcodePage> {
color: buttonColor,
),
fontSize: 16,
onPressed: (){
onPressed: () {
Navigator.pop(context);
},
),
@ -118,7 +133,7 @@ class _InputBarcodePageState extends BaseStoreState<InputBarcodePage> {
);
}
Widget inputWidget(){
Widget inputWidget() {
return Container(
padding: EdgeInsets.only(left: 30, right: 30),
child: Column(
@ -130,28 +145,35 @@ class _InputBarcodePageState extends BaseStoreState<InputBarcodePage> {
margin: EdgeInsets.symmetric(horizontal: 10),
// height: 60,
alignment: Alignment.center,
child: Text("商品条码", style: TextStyle(color: Colors.black, fontSize: ScreenAdapterUtils.setSp(16)),),
child: Text(
"商品条码",
style: TextStyle(
color: Colors.black,
fontSize: ScreenAdapterUtils.setSp(16)),
),
),
Container(width: 15,),
Expanded(
child: Container(
height: 60,
alignment: Alignment.center,
child: CupertinoTextField(
onChanged: (string){
setState(() {});
},
controller: _textEditcontroller,
placeholder: "请输入条码",
decoration: BoxDecoration(
),
maxLength: 13,
maxLines: 1,
style: TextStyle(fontSize: ScreenAdapterUtils.setSp(15), color: Colors.black),
textAlign: TextAlign.left,
),
)
Container(
width: 15,
),
Expanded(
child: Container(
height: 60,
alignment: Alignment.center,
child: CupertinoTextField(
onChanged: (string) {
setState(() {});
},
controller: _textEditcontroller,
placeholder: "请输入条码",
decoration: BoxDecoration(),
maxLength: 13,
maxLines: 1,
style: TextStyle(
fontSize: ScreenAdapterUtils.setSp(15),
color: Colors.black),
textAlign: TextAlign.left,
),
)),
],
),
Container(
@ -165,7 +187,7 @@ class _InputBarcodePageState extends BaseStoreState<InputBarcodePage> {
_getGoodsWithCode(String code) async {
ResultData resultData = await HttpManager.post(GoodsApi.goods_code_search, {
"code":code,
"code": code,
});
if (!resultData.result) {
showError(resultData.msg);
@ -180,8 +202,8 @@ class _InputBarcodePageState extends BaseStoreState<InputBarcodePage> {
if (TextUtils.isEmpty(goodsId)) {
return;
}
AppRouter.pushAndReplaced(globalContext, RouteName.COMMODITY_PAGE, arguments: CommodityDetailPage.setArguments(int.parse(goodsId)));
// AppRouter.pushAndReplaced(globalContext, RouteName.COMMODITY_PAGE, arguments: CommodityDetailPage.setArguments(int.parse(goodsId)));
Get.to(()=>QRScarerResultPage());
return;
}
}

@ -1,11 +1,10 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_qr_reader/flutter_qr_reader.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'package:recook/base/base_store_state.dart';
@ -14,17 +13,18 @@ import 'package:recook/constants/header.dart';
import 'package:recook/constants/styles.dart';
import 'package:recook/manager/http_manager.dart';
import 'package:recook/models/base_model.dart';
import 'package:recook/pages/home/barcode/qr_scaner_result_page.dart';
import 'package:recook/pages/home/classify/commodity_detail_page.dart';
import 'package:recook/utils/image_utils.dart';
import 'package:recook/widgets/custom_app_bar.dart';
import 'package:recook/widgets/custom_image_button.dart';
class PhotosFailBarcodePage extends StatefulWidget{
class PhotosFailBarcodePage extends StatefulWidget {
final Map arguments;
const PhotosFailBarcodePage({Key key, this.arguments}) : super(key: key);
static setArguments(String code, String message, File image){
static setArguments(String code, String message, File image) {
return {
"code": code,
"message": message,
@ -38,12 +38,13 @@ class PhotosFailBarcodePage extends StatefulWidget{
}
}
class _PhotosFailBarcodePageState extends BaseStoreState<PhotosFailBarcodePage>{
class _PhotosFailBarcodePageState
extends BaseStoreState<PhotosFailBarcodePage> {
String _code;
String _message;
File _image;
@override
void initState() {
void initState() {
super.initState();
if (widget.arguments != null) {
_code = widget.arguments["code"];
@ -67,7 +68,7 @@ class _PhotosFailBarcodePageState extends BaseStoreState<PhotosFailBarcodePage>{
);
}
_bodyWidget(){
_bodyWidget() {
double width = MediaQuery.of(context).size.width;
Color buttonColor = Color(0xffE98787);
return Container(
@ -77,17 +78,28 @@ class _PhotosFailBarcodePageState extends BaseStoreState<PhotosFailBarcodePage>{
Container(
height: ScreenAdapterUtils.setHeight(150),
width: MediaQuery.of(context).size.width,
child: Image.file(_image, fit: BoxFit.contain,),
child: Image.file(
_image,
fit: BoxFit.contain,
),
),
Container(
alignment: Alignment.centerLeft,
width: width,
padding: EdgeInsets.only(left: 30, top: 20),
child: Text(_message==null?"商品未录入":_message, style: TextStyle(color: Colors.black, fontSize: ScreenAdapterUtils.setSp(22)),),
child: Text(
_message == null ? "商品未录入" : _message,
style: TextStyle(
color: Colors.black, fontSize: ScreenAdapterUtils.setSp(22)),
),
),
_codeWidget(),
Container(
padding: EdgeInsets.only(left: 30, right: 30, top: 100,),
padding: EdgeInsets.only(
left: 30,
right: 30,
top: 100,
),
child: CustomImageButton(
height: ScreenAdapterUtils.setHeight(36),
backgroundColor: AppColor.themeColor,
@ -95,7 +107,8 @@ class _PhotosFailBarcodePageState extends BaseStoreState<PhotosFailBarcodePage>{
color: Colors.white,
fontSize: 16,
onPressed: () async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
var image =
await ImagePicker.pickImage(source: ImageSource.gallery);
File cropFile = await ImageUtils.cropImage(image);
if (cropFile == null) {
return;
@ -103,11 +116,15 @@ class _PhotosFailBarcodePageState extends BaseStoreState<PhotosFailBarcodePage>{
File imageFile = cropFile;
final rest = await FlutterQrReader.imgScan(imageFile);
onScan(rest, image: imageFile);
},
},
),
),
Container(
padding: EdgeInsets.only(left: 30, right: 30, top: 20,),
padding: EdgeInsets.only(
left: 30,
right: 30,
top: 20,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
@ -120,12 +137,15 @@ class _PhotosFailBarcodePageState extends BaseStoreState<PhotosFailBarcodePage>{
color: buttonColor,
),
fontSize: 16,
onPressed: (){
AppRouter.pushAndReplaced(context, RouteName.BARCODE_SCAN);
onPressed: () {
AppRouter.pushAndReplaced(
context, RouteName.BARCODE_SCAN);
},
),
),
Container(width: 30,),
Container(
width: 30,
),
Expanded(
child: CustomImageButton(
height: ScreenAdapterUtils.setHeight(36),
@ -135,7 +155,7 @@ class _PhotosFailBarcodePageState extends BaseStoreState<PhotosFailBarcodePage>{
color: buttonColor,
),
fontSize: 16,
onPressed: (){
onPressed: () {
Navigator.pop(context);
},
),
@ -147,56 +167,67 @@ class _PhotosFailBarcodePageState extends BaseStoreState<PhotosFailBarcodePage>{
),
);
}
_codeWidget(){
_codeWidget() {
return Container(
padding: EdgeInsets.only(left: 30, right: 30),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(horizontal: 0),
// height: 60,
alignment: Alignment.center,
child: Text("扫码结果", style: TextStyle(color: Colors.black, fontSize: ScreenAdapterUtils.setSp(16)),),
),
Container(width: 15,),
Expanded(
child: Container(
height: 60,
alignment: Alignment.centerLeft,
child: Text(_code, style: TextStyle(color: Colors.black.withOpacity(0.5), fontSize: ScreenAdapterUtils.setSp(15)),),
padding: EdgeInsets.only(left: 30, right: 30),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(horizontal: 0),
// height: 60,
alignment: Alignment.center,
child: Text(
"扫码结果",
style: TextStyle(
color: Colors.black,
fontSize: ScreenAdapterUtils.setSp(16)),
),
),
),
],
),
Container(
height: 1,
color: AppColor.frenchColor,
)
],
)
);
Container(
width: 15,
),
Expanded(
child: Container(
height: 60,
alignment: Alignment.centerLeft,
child: Text(
_code,
style: TextStyle(
color: Colors.black.withOpacity(0.5),
fontSize: ScreenAdapterUtils.setSp(15)),
),
),
),
],
),
Container(
height: 1,
color: AppColor.frenchColor,
)
],
));
}
Future onScan(String data, {File image}) async{
if (!TextUtils.isEmpty(data)){
_getGoodsWithCode(data, (goodsId){
AppRouter.pushAndReplaced(globalContext, RouteName.COMMODITY_PAGE, arguments: CommodityDetailPage.setArguments(int.parse(goodsId)));
Future onScan(String data, {File image}) async {
if (!TextUtils.isEmpty(data)) {
_getGoodsWithCode(data, (goodsId) {
Get.to(() => QRScarerResultPage());
// AppRouter.pushAndReplaced(globalContext, RouteName.COMMODITY_PAGE, arguments: CommodityDetailPage.setArguments(int.parse(goodsId)));
return;
}, image: image);
}else{
} else {
showError("图片识别失败...");
}
}
_getGoodsWithCode(String code, Function callBack, {File image}) async {
ResultData resultData = await HttpManager.post(GoodsApi.goods_code_search, {
"code":code,
"code": code,
});
if (!resultData.result) {
_refreshState(code, resultData.msg, image);
@ -217,11 +248,10 @@ class _PhotosFailBarcodePageState extends BaseStoreState<PhotosFailBarcodePage>{
return;
}
_refreshState(code, message, image){
_refreshState(code, message, image) {
_code = code;
_message = message;
_image = image;
setState(() {});
}
}

@ -0,0 +1,70 @@
import 'package:flutter/material.dart';
import 'package:recook/constants/constants.dart';
import 'package:recook/widgets/custom_image_button.dart';
import 'package:recook/widgets/recook/recook_scaffold.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:velocity_x/velocity_x.dart';
class QRScarerResultPage extends StatefulWidget {
QRScarerResultPage({Key key}) : super(key: key);
@override
_QRScarerResultPageState createState() => _QRScarerResultPageState();
}
class _QRScarerResultPageState extends State<QRScarerResultPage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return RecookScaffold(
title: '扫码购物',
body: ListView(
children: [],
),
bottomNavi: Row(
children: [_shopButton().expand(), 2.widthBox, _buyButton().expand()],
)
.pSymmetric(h: 32.w)
.box
.color(Colors.white)
.padding(EdgeInsets.only(bottom: ScreenUtil().bottomBarHeight))
.width(double.infinity)
.height(128.w)
.make(),
);
}
Widget _buyButton() {
return CustomImageButton(
title: "立即购买",
color: Colors.white,
height: 80.w,
boxDecoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Color(0xffc81a3e), Color(0xfffa4968)]),
borderRadius: BorderRadius.only(
topRight: Radius.circular(30), bottomRight: Radius.circular(30))),
fontSize: 32.sp,
onPressed: () {},
);
}
Widget _shopButton() {
return CustomImageButton(
title: "加入购物车",
color: Colors.white,
height: 80.w,
boxDecoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Color(0xff979797), Color(0xff5d5e5d)]),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30), bottomLeft: Radius.circular(30))),
fontSize: 32.sp,
onPressed: () {},
);
}
}
Loading…
Cancel
Save