Merge branch 'master' of tzw/fcs into master

This commit is contained in:
2021-01-09 13:31:25 +00:00
committed by Gogs
16 changed files with 583 additions and 322 deletions

View File

@@ -300,6 +300,7 @@
"box.min_caton.form.title":"Mix Carton", "box.min_caton.form.title":"Mix Carton",
"box.mix_carton_btn":"Create mix carton", "box.mix_carton_btn":"Create mix carton",
"box.mix_type":"Mix Box Types", "box.mix_type":"Mix Box Types",
"box.selection":"Carton Selection",
"Boxes End ================================================================":"", "Boxes End ================================================================":"",
"Delivery Start ================================================================":"", "Delivery Start ================================================================":"",

View File

@@ -300,6 +300,7 @@
"box.min_caton.form.title":"Mix Carton", "box.min_caton.form.title":"Mix Carton",
"box.mix_carton_btn":"Create mix carton", "box.mix_carton_btn":"Create mix carton",
"box.mix_type":"Mix Box Types", "box.mix_type":"Mix Box Types",
"box.selection":"သေတ္တာ ရွေးချယ်ခြင်း",
"Boxes End ================================================================":"", "Boxes End ================================================================":"",
"Delivery Start ================================================================":"", "Delivery Start ================================================================":"",

View File

@@ -1,5 +1,8 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:fcs/domain/constants.dart';
import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/helpers/api_helper.dart'; import 'package:fcs/helpers/api_helper.dart';
import 'package:fcs/helpers/firebase_helper.dart'; import 'package:fcs/helpers/firebase_helper.dart';
@@ -31,4 +34,32 @@ class CartonDataProvider {
return await requestAPI("/cartons/deliver", "PUT", return await requestAPI("/cartons/deliver", "PUT",
payload: carton.toMap(), token: await getToken()); payload: carton.toMap(), token: await getToken());
} }
Future<List<Carton>> searchCarton(String term) async {
if (term == null || term == '') return List();
// var bytes = utf8.encode(term);
// var base64Str = base64.encode(bytes);
// HtmlEscape htmlEscape = const HtmlEscape();
// String escapeBuyer = htmlEscape.convert(base64Str);
try {
String path = "/$cartons_collection";
var querySnap = await Firestore.instance
.collection(path)
.where("carton_number", isEqualTo: term)
.where("carton_type",
whereIn: [carton_from_packages, carton_from_cargos])
.where("status", isEqualTo: carton_packed_status)
.where("is_deleted", isEqualTo: false)
.orderBy("user_name")
.getDocuments();
return querySnap.documents
.map((e) => Carton.fromMap(e.data, e.documentID))
.toList();
} catch (e) {
log.warning("carton error:" + e.toString());
return null;
}
}
} }

View File

@@ -33,4 +33,9 @@ class CartonServiceImp implements CartonService {
Future<void> deliver(Carton carton) { Future<void> deliver(Carton carton) {
return cartonDataProvider.deliver(carton); return cartonDataProvider.deliver(carton);
} }
@override
Future<List<Carton>> searchCarton(String term) {
return cartonDataProvider.searchCarton(term);
}
} }

View File

@@ -5,4 +5,5 @@ abstract class CartonService {
Future<void> updateCarton(Carton carton); Future<void> updateCarton(Carton carton);
Future<void> deleteCarton(Carton carton); Future<void> deleteCarton(Carton carton);
Future<void> deliver(Carton carton); Future<void> deliver(Carton carton);
Future<List<Carton>> searchCarton(String term);
} }

View File

@@ -78,6 +78,7 @@ const shipment_courier_dropoff = "Courier drop off";
//Carton types //Carton types
const carton_from_packages = "From packages"; const carton_from_packages = "From packages";
const carton_from_cargos="From cargos";
const carton_from_shipments = "From shipments"; const carton_from_shipments = "From shipments";
const carton_mix_carton = "Mix carton"; const carton_mix_carton = "Mix carton";
const carton_small_bag = "Small bag"; const carton_small_bag = "Small bag";

View File

@@ -12,8 +12,10 @@ class Carton {
String id; String id;
String shipmentID; String shipmentID;
String shipmentNumber; String shipmentNumber;
String senderID;
String senderFCSID; String senderFCSID;
String senderName; String senderName;
String receiverID;
String receiverFCSID; String receiverFCSID;
String receiverName; String receiverName;
String receiverAddress; String receiverAddress;
@@ -38,7 +40,6 @@ class Carton {
String mixCartonNumber; String mixCartonNumber;
String cartonSizeID; String cartonSizeID;
String cartonSizeName; String cartonSizeName;
String mixBoxType;
int rate; int rate;
int weight; int weight;
@@ -56,6 +57,10 @@ class Carton {
DeliveryAddress deliveryAddress; DeliveryAddress deliveryAddress;
Shipment shipment; Shipment shipment;
//for mix box
String mixBoxType;
List<Carton> mixCartons;
int get amount => rate != null && weight != null ? rate * weight : 0; int get amount => rate != null && weight != null ? rate * weight : 0;
String get packageNumber => String get packageNumber =>
@@ -126,8 +131,10 @@ class Carton {
{this.id, {this.id,
this.shipmentID, this.shipmentID,
this.shipmentNumber, this.shipmentNumber,
this.senderID,
this.senderFCSID, this.senderFCSID,
this.senderName, this.senderName,
this.receiverID,
this.receiverFCSID, this.receiverFCSID,
this.receiverName, this.receiverName,
this.receiverNumber, this.receiverNumber,
@@ -164,13 +171,15 @@ class Carton {
this.deliveryAddress, this.deliveryAddress,
this.cartonSizeID, this.cartonSizeID,
this.cartonSizeName, this.cartonSizeName,
this.mixBoxType}); this.mixBoxType,
this.mixCartons});
Map<String, dynamic> toMap() { Map<String, dynamic> toMap() {
List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList(); List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList();
List _packages = packages?.map((c) => c.toJson())?.toList(); List _packages = packages?.map((c) => c.toJson())?.toList();
List _mixCartons = mixCartons?.map((c) => c.toJson())?.toList();
return { return {
"id": id, 'id': id,
'fcs_shipment_id': fcsShipmentID, 'fcs_shipment_id': fcsShipmentID,
'user_id': userID, 'user_id': userID,
'cargo_types': _cargoTypes, 'cargo_types': _cargoTypes,
@@ -181,6 +190,14 @@ class Carton {
'delivery_address': deliveryAddress?.toMap(), 'delivery_address': deliveryAddress?.toMap(),
'carton_type': cartonType, 'carton_type': cartonType,
'mix_carton_id': mixCartonID, 'mix_carton_id': mixCartonID,
'mix_box_type': mixBoxType,
'mix_cartons': _mixCartons,
'receiver_id': receiverID,
'receiver_fcs_id': receiverFCSID,
'receiver_name': receiverName,
'sender_id': senderID,
'sender_fcs_id': senderFCSID,
'sender_name': senderName
}; };
} }
@@ -192,30 +209,71 @@ class Carton {
List<Map<String, dynamic>>.from(map['cargo_types'] ?? []); List<Map<String, dynamic>>.from(map['cargo_types'] ?? []);
var cargoTypes = var cargoTypes =
cargoTypesMaps.map((e) => CargoType.fromMap(e, e["id"])).toList(); cargoTypesMaps.map((e) => CargoType.fromMap(e, e["id"])).toList();
var mixCartonsMaps =
List<Map<String, dynamic>>.from(map['mix_cartons'] ?? []);
var _mixCartons =
mixCartonsMaps.map((e) => Carton.fromMap(e, e["id"])).toList();
return Carton( return Carton(
id: docID, id: docID,
arrivedDate: _arrivedDate != null ? _arrivedDate.toDate() : null, arrivedDate: _arrivedDate != null ? _arrivedDate.toDate() : null,
shipmentID: map['shipment_id'], shipmentID: map['shipment_id'],
shipmentNumber: map['shipment_number'], shipmentNumber: map['shipment_number'],
receiverNumber: map['receiver_number'], receiverNumber: map['receiver_number'],
boxNumber: map['box_number'], boxNumber: map['box_number'],
length: double.tryParse(map['length']?.toString()), length: double.tryParse(map['length']?.toString()),
width: double.tryParse(map['width']?.toString()), width: double.tryParse(map['width']?.toString()),
height: double.tryParse(map['height']?.toString()), height: double.tryParse(map['height']?.toString()),
userName: map['user_name'], userName: map['user_name'],
fcsID: map['fcs_id'], fcsID: map['fcs_id'],
cartonType: map['carton_type'], cartonType: map['carton_type'],
cartonNumber: map['carton_number'], cartonNumber: map['carton_number'],
userID: map['user_id'], userID: map['user_id'],
fcsShipmentID: map['fcs_shipment_id'], fcsShipmentID: map['fcs_shipment_id'],
fcsShipmentNumber: map['fcs_shipment_number'], fcsShipmentNumber: map['fcs_shipment_number'],
isShipmentCarton: map['is_shipment_carton'], isShipmentCarton: map['is_shipment_carton'],
mixCartonID: map['mix_carton_id'], mixCartonID: map['mix_carton_id'],
mixCartonNumber: map['mix_carton_number'], mixCartonNumber: map['mix_carton_number'],
status: map['status'], status: map['status'],
packageIDs: List<String>.from(map['package_ids'] ?? []), packageIDs: List<String>.from(map['package_ids'] ?? []),
deliveryAddress: _da, deliveryAddress: _da,
cargoTypes: cargoTypes); cargoTypes: cargoTypes,
mixBoxType: map['mix_box_type'],
mixCartons: _mixCartons,
receiverID: map['receiver_id'],
receiverFCSID: map['receiver_fcs_id'],
receiverName: map['receiver_name'],
senderID: map['sender_id'],
senderFCSID: map['sender_fcs_id'],
senderName: map['sender_name'],
);
}
Map<String, dynamic> toJson() {
List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList();
List _packages = packages?.map((c) => c.toJson())?.toList();
List _mixCartons = mixCartons?.map((c) => c.toJson())?.toList();
return {
'id': id,
'fcs_shipment_id': fcsShipmentID,
'user_id': userID,
'cargo_types': _cargoTypes,
'packages': _packages,
'length': length,
'width': width,
'height': height,
'delivery_address': deliveryAddress?.toMap(),
'carton_type': cartonType,
'mix_carton_id': mixCartonID,
'mix_box_type': mixBoxType,
'mix_cartons': _mixCartons,
'receiver_id': receiverID,
'receiver_fcs_id': receiverFCSID,
'receiver_name': receiverName,
'sender_id': senderID,
'sender_fcs_id': senderFCSID,
'sender_name': senderName
};
} }
@override @override

View File

@@ -105,9 +105,7 @@ class _CargoTableState extends State<CargoTable> {
String _t = await showDialog( String _t = await showDialog(
context: context, context: context,
builder: (_) => DialogInput( builder: (_) => DialogInput(
label: "cargo.qty", label: "cargo.qty", value: c.qty.toString()));
value: c.qty.toString(),
isQty: true));
if (_t == null) return; if (_t == null) return;
setState(() { setState(() {

View File

@@ -33,9 +33,7 @@ import 'package:flutter_icons/flutter_icons.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'cargo_type_addtion.dart'; import 'cargo_type_addtion.dart';
import 'carton_cargo_table.dart'; import 'carton_cargo_table.dart';
import 'carton_list_row.dart';
import 'carton_row.dart'; import 'carton_row.dart';
import 'mix_carton_editor.dart';
import 'model/carton_model.dart'; import 'model/carton_model.dart';
import '../carton_size/model/carton_size_model.dart'; import '../carton_size/model/carton_size_model.dart';
import 'package_carton_editor.dart'; import 'package_carton_editor.dart';
@@ -62,15 +60,23 @@ class _CartonEditorState extends State<CartonEditor> {
bool _isNew; bool _isNew;
User _user; User _user;
String _selectedCartonType; String _selectedCartonType;
String _selectedMixBoxType;
double volumetricRatio = 0; double volumetricRatio = 0;
double shipmentWeight = 0; double shipmentWeight = 0;
FcsShipment _fcsShipment; FcsShipment _fcsShipment;
List<FcsShipment> _fcsShipments; List<FcsShipment> _fcsShipments;
List<Carton> _cartons = []; List<Carton> _cartons = [];
List<Carton> _mixCartons = [];
CartonSize selectedCatonSize; CartonSize selectedCatonSize;
//for mix carton
List<Carton> _mixCartons = [];
String _selectedMixBoxType;
//for carton from cargos
User consignee;
User sender;
List<Carton> _cartonsForCargos = [];
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@@ -93,9 +99,20 @@ class _CartonEditorState extends State<CartonEditor> {
_cargoTypes = List.from(_carton.cargoTypes); _cargoTypes = List.from(_carton.cargoTypes);
_isNew = false; _isNew = false;
_user = User(fcsID: _carton.fcsID, name: _carton.userName); _user = User(fcsID: _carton.fcsID, name: _carton.userName);
_loadPackages(); consignee =
_getDeliverAddresses(); User(fcsID: _carton.receiverFCSID, name: _carton.receiverName);
_getCartonSize(); sender = User(fcsID: _carton.senderID, name: _carton.senderName);
_selectedMixBoxType = _carton.mixBoxType ?? "";
this._mixCartons =
_carton.mixCartons == null ? [] : List.from(_carton.mixCartons);
bool isMixBox = _carton.cartonType == carton_mix_box;
bool isFromPackages = _carton.cartonType == carton_from_packages;
if (isFromPackages) _loadPackages();
if (!isMixBox) {
_getDeliverAddresses();
_getCartonSize();
}
} else { } else {
_carton = Carton( _carton = Carton(
cargoTypes: [], cargoTypes: [],
@@ -108,11 +125,6 @@ class _CartonEditorState extends State<CartonEditor> {
_selectedCartonType = carton_from_packages; _selectedCartonType = carton_from_packages;
_selectedMixBoxType = mix_delivery; _selectedMixBoxType = mix_delivery;
_loadFcsShipments(); _loadFcsShipments();
// _mixCartons = [
// Carton(cartonNumber: "A100B-1#1", userName: "Seven 7"),
// Carton(cartonNumber: "A100B-1#2", userName: "Seven 7"),
// ];
} }
} }
@@ -188,8 +200,10 @@ class _CartonEditorState extends State<CartonEditor> {
_getDeliverAddresses() async { _getDeliverAddresses() async {
var addressModel = var addressModel =
Provider.of<DeliveryAddressModel>(context, listen: false); Provider.of<DeliveryAddressModel>(context, listen: false);
this._deliveryAddresses = bool isFromPackages = _carton.cartonType == carton_from_packages;
await addressModel.getDeliveryAddresses(_carton.userID); this._deliveryAddresses = isFromPackages
? await addressModel.getDeliveryAddresses(_carton.userID)
: await addressModel.getDeliveryAddresses(_carton.receiverID);
} }
_getCartonSize() { _getCartonSize() {
@@ -216,6 +230,8 @@ class _CartonEditorState extends State<CartonEditor> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var boxModel = Provider.of<CartonModel>(context); var boxModel = Provider.of<CartonModel>(context);
bool isFromPackages = _selectedCartonType == carton_from_packages;
bool isFromCargos = _selectedCartonType == carton_from_cargos;
bool isMixBox = _selectedCartonType == carton_mix_box; bool isMixBox = _selectedCartonType == carton_mix_box;
final shipmentBox = DisplayText( final shipmentBox = DisplayText(
@@ -348,7 +364,11 @@ class _CartonEditorState extends State<CartonEditor> {
Icons.add_circle, Icons.add_circle,
color: primaryColor, color: primaryColor,
), ),
onPressed: _addMixCarton, onPressed: () async {
searchCarton(context, callbackCartonSelect: (c) {
_addMixCarton(c);
});
},
), ),
), ),
); );
@@ -405,6 +425,80 @@ class _CartonEditorState extends State<CartonEditor> {
SizedBox(child: heightBox, width: 80), SizedBox(child: heightBox, width: 80),
], ],
); );
final createMixCarton = LocalButton(
textKey: _isNew ? "box.mix_carton_btn" : "box.cargo.save.btn",
callBack: _creatMixCarton,
);
final consigneefcsIDBox = Row(
children: <Widget>[
Expanded(
child: DisplayText(
text: consignee != null ? consignee.fcsID : "",
labelTextKey: "processing.fcs.id",
icon: FcsIDIcon(),
)),
IconButton(
icon: Icon(Icons.search, color: primaryColor),
onPressed: () => searchUser(context, callbackUserSelect: (u) {
setState(() {
this.consignee = u;
});
})),
],
);
final consigneeNameBox = DisplayText(
text: consignee != null ? consignee.name : "",
labelTextKey: "processing.consignee.name",
maxLines: 2,
iconData: Icons.person,
);
final consigneeBox = Container(
child: Column(
children: [
consigneefcsIDBox,
consigneeNameBox,
],
),
);
final shipperIDBox = Row(
children: <Widget>[
Expanded(
child: DisplayText(
text: sender != null ? sender.fcsID : "",
labelTextKey: "processing.fcs.id",
icon: FcsIDIcon(),
)),
IconButton(
icon: Icon(Icons.search, color: primaryColor),
onPressed: () => searchUser(context, callbackUserSelect: (u) {
setState(() {
this.sender = u;
});
})),
],
);
final shipperNamebox = DisplayText(
text: sender != null ? sender.name : "",
labelTextKey: "processing.shipper.name",
maxLines: 2,
iconData: Icons.person,
);
final shipperBox = Container(
child: Column(
children: [
shipperIDBox,
shipperNamebox,
],
),
);
return LocalProgress( return LocalProgress(
inAsyncCall: _isLoading, inAsyncCall: _isLoading,
child: Scaffold( child: Scaffold(
@@ -451,29 +545,44 @@ class _CartonEditorState extends State<CartonEditor> {
children: _getMixCartons(context, this._mixCartons)), children: _getMixCartons(context, this._mixCartons)),
] ]
: [ : [
fcsIDBox, isFromPackages ? fcsIDBox : Container(),
namebox, isFromPackages ? namebox : Container(),
CartonPackageTable( isFromPackages
packages: _carton.packages, ? CartonPackageTable(
onSelect: (p, checked) { packages: _carton.packages,
if (checked && onSelect: (p, checked) {
_deliveryAddress != null && if (checked &&
p.deliveryAddress?.id != _deliveryAddress.id) { _deliveryAddress != null &&
return; p.deliveryAddress?.id !=
} _deliveryAddress.id) {
setState(() { return;
p.isChecked = checked; }
}); setState(() {
// _populateDeliveryAddress(); p.isChecked = checked;
}, });
), // _populateDeliveryAddress();
},
)
: Container(),
isFromCargos
? Container(
padding: const EdgeInsets.only(top: 15),
child: Row(
children: [
Flexible(child: consigneeBox),
Flexible(child: shipperBox)
],
),
)
: Container(),
_isNew ? cartonTitleBox : Container(), _isNew ? cartonTitleBox : Container(),
_isNew _isNew
? Column( ? Column(
children: _getCartons( children: _getCartons(
context, context,
this._cartons, isFromPackages
)) ? this._cartons
: this._cartonsForCargos))
: Container(), : Container(),
_isNew ? Container() : cargoTableTitleBox, _isNew ? Container() : cargoTableTitleBox,
_isNew ? Container() : cargoTableBox, _isNew ? Container() : cargoTableBox,
@@ -510,7 +619,12 @@ class _CartonEditorState extends State<CartonEditor> {
SizedBox( SizedBox(
height: 20, height: 20,
), ),
_isNew ? createBtn : saveBtn, isFromPackages || isFromCargos
? _isNew
? createBtn
: saveBtn
: Container(),
isMixBox ? createMixCarton : Container(),
SizedBox( SizedBox(
height: 20, height: 20,
), ),
@@ -525,18 +639,22 @@ class _CartonEditorState extends State<CartonEditor> {
return cartons.asMap().entries.map((c) { return cartons.asMap().entries.map((c) {
return InkWell( return InkWell(
onTap: () async { onTap: () async {
_loadPackages(); bool isFromPackages = _selectedCartonType == carton_from_packages;
c.value.packages = _carton.packages; bool isFromCargos = _selectedCartonType == carton_from_cargos;
Carton _c = await Navigator.push( if (isFromPackages) {
context, _loadPackages();
CupertinoPageRoute( c.value.packages = _carton.packages;
builder: (context) => Carton _c = await Navigator.push(
PackageCartonEditor(carton: c.value, isNew: false)), context,
); CupertinoPageRoute(
if (_c == null) return; builder: (context) =>
cartons.removeWhere((item) => item.id == _c.id); PackageCartonEditor(carton: c.value, isNew: false)),
cartons.insert(c.key, _c); );
setState(() {}); if (_c == null) return;
cartons.removeWhere((item) => item.id == _c.id);
cartons.insert(c.key, _c);
setState(() {});
}
}, },
child: CartonRow( child: CartonRow(
key: ValueKey(c.value.id), key: ValueKey(c.value.id),
@@ -548,12 +666,12 @@ class _CartonEditorState extends State<CartonEditor> {
List<Widget> _getMixCartons(BuildContext context, List<Carton> cartons) { List<Widget> _getMixCartons(BuildContext context, List<Carton> cartons) {
return cartons.map((c) { return cartons.map((c) {
return InkWell( return CartonRow(
onTap: () {}, key: ValueKey(c.id),
child: CartonRow( box: c,
key: ValueKey(c.id), onRemove: (carton) {
box: c, _removeMixCarton(carton);
), },
); );
}).toList(); }).toList();
} }
@@ -652,12 +770,25 @@ class _CartonEditorState extends State<CartonEditor> {
_addCarton() async { _addCarton() async {
bool isFromPackages = _selectedCartonType == carton_from_packages; bool isFromPackages = _selectedCartonType == carton_from_packages;
bool isFromCargos = _selectedCartonType == carton_from_cargos;
if (_fcsShipment == null && _isNew) {
showMsgDialog(context, "Error", "Please select FCS shipment");
return;
}
if (_user == null && isFromPackages) { if (_user == null && isFromPackages) {
showMsgDialog(context, "Error", "Please select FCS ID"); showMsgDialog(context, "Error", "Please select FCS ID");
return; return;
} }
if (_fcsShipment == null && _isNew) {
showMsgDialog(context, "Error", "Please select FCS shipment"); if (consignee == null && isFromCargos) {
showMsgDialog(context, "Error", "Please select consignee's FCS ID");
return;
}
if (sender == null && isFromCargos) {
showMsgDialog(context, "Error", "Please select sender's FCS ID");
return; return;
} }
@@ -669,16 +800,26 @@ class _CartonEditorState extends State<CartonEditor> {
carton.id = _carton.id; carton.id = _carton.id;
carton.cartonType = _selectedCartonType; carton.cartonType = _selectedCartonType;
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID; carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
carton.userID = _user?.id; if (isFromPackages) {
carton.fcsID = _user?.fcsID; carton.userID = _user?.id;
carton.userName = _user?.name; carton.fcsID = _user?.fcsID;
carton.packages = _carton.packages.where((e) => e.isChecked).toList(); carton.userName = _user?.name;
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
}
if (isFromCargos) {
carton.receiverID = consignee?.id;
carton.receiverFCSID = consignee?.fcsID;
carton.receiverName = consignee?.name;
carton.senderID = sender?.id;
carton.senderFCSID = sender?.fcsID;
carton.senderName = sender?.name;
}
carton.cargoTypes = _carton.cargoTypes; carton.cargoTypes = _carton.cargoTypes;
carton.length = l; carton.length = l;
carton.width = w; carton.width = w;
carton.height = h; carton.height = h;
carton.deliveryAddress = _carton.deliveryAddress; carton.deliveryAddress = _carton.deliveryAddress;
try { try {
@@ -691,43 +832,85 @@ class _CartonEditorState extends State<CartonEditor> {
if (_c == null) return; if (_c == null) return;
var cartonModel = Provider.of<CartonModel>(context, listen: false); var cartonModel = Provider.of<CartonModel>(context, listen: false);
Carton _carton = await cartonModel.getCarton(_c.id); Carton _carton = await cartonModel.getCarton(_c.id);
_cartons.add(_carton); if (isFromPackages) {
_cartons.add(_carton);
}
if (isFromCargos) {
_cartonsForCargos.add(_carton);
}
setState(() {}); setState(() {});
} catch (e) { } catch (e) {
showMsgDialog(context, "Error", e.toString()); showMsgDialog(context, "Error", e.toString());
} }
} }
_addMixCarton() async { _addMixCarton(Carton carton) {
if (carton == null) return;
if (this._mixCartons.any((c) => c.id == carton.id)) return;
setState(() {
this._mixCartons.add(carton);
});
}
_removeMixCarton(Carton carton) {
setState(() {
this._mixCartons.removeWhere((c) => c.id == carton.id);
});
}
_creatMixCarton() async {
if (_fcsShipment == null && _isNew) { if (_fcsShipment == null && _isNew) {
showMsgDialog(context, "Error", "Please select FCS shipment"); showMsgDialog(context, "Error", "Please select FCS shipment");
return; return;
} }
if ((this._mixCartons?.length ?? 0) == 0) {
showMsgDialog(context, "Error", "Expect at least one carton");
return;
}
Carton carton = Carton(); Carton carton = Carton();
carton.id = _carton.id; carton.id = _carton.id;
carton.cartonType = _selectedCartonType; carton.cartonType = _selectedCartonType;
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID; carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
carton.mixBoxType = _selectedMixBoxType; carton.mixBoxType = _selectedMixBoxType;
await Navigator.push( carton.mixCartons = this._mixCartons;
context, setState(() {
CupertinoPageRoute(builder: (context) => MixCartonEditor(box: carton)), _isLoading = true;
); });
try {
CartonModel cartonModel =
Provider.of<CartonModel>(context, listen: false);
if (_isNew) {
await cartonModel.createMixCarton(carton);
} else {
await cartonModel.updateMixCarton(carton);
}
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
} }
_save() async { _save() async {
bool isFromPackages = _selectedCartonType == carton_from_packages; bool isFromPackages = _selectedCartonType == carton_from_packages;
if ((_cargoTypes?.length ?? 0) == 0 && (isFromPackages)) { bool isFromCargos = _selectedCartonType == carton_from_cargos;
if ((_cargoTypes?.length ?? 0) == 0 && (isFromPackages || isFromCargos)) {
showMsgDialog(context, "Error", "Expect at least one cargo type"); showMsgDialog(context, "Error", "Expect at least one cargo type");
return; return;
} }
double l = double.parse(_lengthController.text, (s) => 0); double l = double.parse(_lengthController.text, (s) => 0);
double w = double.parse(_widthController.text, (s) => 0); double w = double.parse(_widthController.text, (s) => 0);
double h = double.parse(_heightController.text, (s) => 0); double h = double.parse(_heightController.text, (s) => 0);
if ((l <= 0 || w <= 0 || h <= 0) && isFromPackages) { if ((l <= 0 || w <= 0 || h <= 0) && (isFromPackages || isFromCargos)) {
showMsgDialog(context, "Error", "Invalid dimension"); showMsgDialog(context, "Error", "Invalid dimension");
return; return;
} }
if (_deliveryAddress == null && (isFromPackages)) { if (_deliveryAddress == null && (isFromPackages || isFromCargos)) {
showMsgDialog(context, "Error", "Invalid delivery address"); showMsgDialog(context, "Error", "Invalid delivery address");
return; return;
} }
@@ -736,8 +919,15 @@ class _CartonEditorState extends State<CartonEditor> {
carton.id = _carton.id; carton.id = _carton.id;
carton.cartonType = _selectedCartonType; carton.cartonType = _selectedCartonType;
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID; carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
carton.userID = _user?.id; if (isFromPackages) {
carton.packages = _carton.packages.where((e) => e.isChecked).toList(); carton.userID = _user?.id;
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
}
if (isFromCargos) {
carton.receiverID = consignee?.id;
carton.senderID = sender?.id;
}
carton.cargoTypes = _cargoTypes; carton.cargoTypes = _cargoTypes;
carton.length = l; carton.length = l;
carton.width = w; carton.width = w;

View File

@@ -51,19 +51,21 @@ class _CartonInfoState extends State<CartonInfo> {
double volumetricRatio = 0; double volumetricRatio = 0;
double shipmentWeight = 0; double shipmentWeight = 0;
String selectMixBoxType; String selectMixBoxType;
List<Carton> _cartons = []; List<Carton> _mixCartons = [];
bool isMixBox; bool isMixBox;
bool isFromShipments; bool isFromShipments;
bool isFromPackages; bool isFromPackages;
bool isSmallBag; bool isSmallBag;
bool isFromCartons;
bool isEdiable; bool isEdiable;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_box = widget.box; _box = widget.box;
// _box.cartonType = carton_from_cargos;
// _box.cartonType = carton_mix_box;
//for shipment weight //for shipment weight
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false) volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
.rate .rate
@@ -86,21 +88,13 @@ class _CartonInfoState extends State<CartonInfo> {
isFromShipments = _box.cartonType == carton_from_shipments; isFromShipments = _box.cartonType == carton_from_shipments;
isFromPackages = _box.cartonType == carton_from_packages; isFromPackages = _box.cartonType == carton_from_packages;
isSmallBag = _box.cartonType == carton_small_bag; isSmallBag = _box.cartonType == carton_small_bag;
isEdiable = !isMixBox && isFromCartons = _box.cartonType == carton_from_cargos;
(isFromPackages || isSmallBag) &&
isEdiable = (isFromPackages || isMixBox || isFromCartons) &&
_box.status == carton_packed_status; _box.status == carton_packed_status;
selectMixBoxType = _box.mixBoxType ?? "Mix Delivery"; selectMixBoxType = _box.mixBoxType ?? "";
_mixCartons = _box.mixCartons == null ? [] : _box.mixCartons;
getCartonSize(); getCartonSize();
_cartons = [
Carton(
cartonNumber: "A100B-1#1",
cargoTypes: [CargoType(name: "General", weight: 12)],
userName: "Seven 7"),
Carton(
cartonNumber: "A100B-1#2",
cargoTypes: [CargoType(name: "General", weight: 12)],
userName: "Seven 7"),
];
} }
getCartonSize() { getCartonSize() {
@@ -180,6 +174,55 @@ class _CartonInfoState extends State<CartonInfo> {
iconData: Icons.person, iconData: Icons.person,
); );
final consigneefcsIDBox = DisplayText(
text: _box.receiverFCSID != null ? _box.receiverFCSID : "",
labelTextKey: "processing.fcs.id",
icon: FcsIDIcon(),
);
final consigneeNameBox = DisplayText(
text: _box.receiverName != null ? _box.receiverName : "",
labelTextKey: "processing.consignee.name",
maxLines: 2,
iconData: Icons.person,
);
final consigneeBox = Container(
child: Column(
children: [
consigneefcsIDBox,
consigneeNameBox,
],
),
);
final shipperIDBox = Row(
children: <Widget>[
Expanded(
child: DisplayText(
text: _box.senderFCSID != null ? _box.senderFCSID : "",
labelTextKey: "processing.fcs.id",
icon: FcsIDIcon(),
)),
],
);
final shipperNamebox = DisplayText(
text: _box.senderName != null ? _box.senderName : "",
labelTextKey: "processing.shipper.name",
maxLines: 2,
iconData: Icons.person,
);
final shipperBox = Container(
child: Column(
children: [
shipperIDBox,
shipperNamebox,
],
),
);
final lengthBox = LengthPicker( final lengthBox = LengthPicker(
controller: _lengthController, controller: _lengthController,
lableKey: "box.length", lableKey: "box.length",
@@ -291,17 +334,29 @@ class _CartonInfoState extends State<CartonInfo> {
cartonTypeBox, cartonTypeBox,
LocalTitle(textKey: "box.shipment_info"), LocalTitle(textKey: "box.shipment_info"),
shipmentBox, shipmentBox,
isSmallBag ? mixCartonNumberBox : Container(), // isSmallBag ? mixCartonNumberBox : Container(),
isMixBox ? Container() : fcsIDBox,
isMixBox ? Container() : customerNameBox,
isMixBox ? mixTypeBox : Container(),
isMixBox ? LocalTitle(textKey: "boxes.title") : Container(),
isMixBox isMixBox
? Column( ? Container()
children: _getCartons( : isFromPackages
context, ? fcsIDBox
this._cartons, : Container(),
)) isMixBox
? Container()
: isFromPackages
? customerNameBox
: Container(),
isFromCartons
? Row(
children: [
Flexible(child: consigneeBox),
Flexible(child: shipperBox)
],
)
: Container(),
isMixBox ? mixTypeBox : Container(),
isMixBox ? LocalTitle(textKey: "box.mix_caton_title") : Container(),
isMixBox
? Column(children: _getCartons(context, this._mixCartons))
: Container(), : Container(),
isFromPackages || isSmallBag isFromPackages || isSmallBag
? CartonPackageTable( ? CartonPackageTable(
@@ -310,7 +365,7 @@ class _CartonInfoState extends State<CartonInfo> {
: Container(), : Container(),
isMixBox ? Container() : LocalTitle(textKey: "box.cargo.type"), isMixBox ? Container() : LocalTitle(textKey: "box.cargo.type"),
isMixBox ? Container() : cargoTableBox, isMixBox ? Container() : cargoTableBox,
...(isFromPackages ...(isFromPackages || isFromCartons
? [ ? [
LocalTitle(textKey: "box.dimension"), LocalTitle(textKey: "box.dimension"),
cartonSizeBox, cartonSizeBox,

View File

@@ -1,145 +0,0 @@
import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/carton/model/carton_model.dart';
import 'package:fcs/pages/carton_search/carton_search.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/widgets/local_button.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/local_title.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'carton_row.dart';
class MixCartonEditor extends StatefulWidget {
final Carton box;
MixCartonEditor({this.box});
@override
_MixCartonEditorState createState() => _MixCartonEditorState();
}
class _MixCartonEditorState extends State<MixCartonEditor> {
Carton _box;
bool _isLoading = false;
bool _isNew;
List<Carton> _cartons = [];
@override
void initState() {
super.initState();
_box = widget.box;
}
@override
Widget build(BuildContext context) {
final createBtn = LocalButton(
textKey: "box.mix_carton_btn",
callBack: _creatCarton,
);
final cargoTableTitleBox = LocalTitle(
textKey: "boxes.title",
trailing: IconButton(
icon: Icon(
Icons.add_circle,
color: primaryColor,
),
onPressed: () => searchCarton(context, callbackCartonSelect: (c) {
_addMixCarton(c);
}),
),
);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
leading: new IconButton(
icon: new Icon(
CupertinoIcons.back,
color: primaryColor,
),
onPressed: () => Navigator.of(context).pop(),
),
shadowColor: Colors.transparent,
backgroundColor: Colors.white,
title: LocalText(
context,
"box.min_caton.form.title",
fontSize: 20,
color: primaryColor,
),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(
children: [
cargoTableTitleBox,
Column(
children: _getCartons(
context,
this._cartons,
)),
SizedBox(
height: 20,
),
createBtn
],
),
),
),
);
}
List<Widget> _getCartons(BuildContext context, List<Carton> cartons) {
return cartons.map((c) {
return CartonRow(
key: ValueKey(c.id),
box: c,
onRemove: (carton) {
_removeMixCarton(carton);
},
);
}).toList();
}
_addMixCarton(Carton carton) {
if (carton == null) return;
if (this._cartons.any((c) => c.cartonNumber == carton.cartonNumber)) return;
setState(() {
this._cartons.add(carton);
});
}
_removeMixCarton(Carton carton) {
setState(() {
this._cartons.remove(carton);
});
}
_creatCarton() {
if ((this._cartons?.length ?? 0) == 0) {
showMsgDialog(context, "Error", "Expect at least one carton");
return;
}
Carton carton = Carton();
carton.id = _box.id;
carton.cartonType = _box.cartonType;
setState(() {
_isLoading = true;
});
try {
CartonModel cartonModel =
Provider.of<CartonModel>(context, listen: false);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
}

View File

@@ -13,6 +13,7 @@ import 'package:logging/logging.dart';
class CartonModel extends BaseModel { class CartonModel extends BaseModel {
List<Carton> _boxes = []; List<Carton> _boxes = [];
List<Carton> cartons = [];
final log = Logger('CartonModel'); final log = Logger('CartonModel');
List<Carton> get boxes => List<Carton> get boxes =>
_selectedIndex == 1 ? _boxes : List<Carton>.from(_delivered.values); _selectedIndex == 1 ? _boxes : List<Carton>.from(_delivered.values);
@@ -22,6 +23,7 @@ class CartonModel extends BaseModel {
bool isLoading = false; bool isLoading = false;
StreamSubscription<QuerySnapshot> listener; StreamSubscription<QuerySnapshot> listener;
StreamSubscription<QuerySnapshot> cartonListener;
static List<ShipmentStatus> statusHistory = [ static List<ShipmentStatus> statusHistory = [
ShipmentStatus(status: "Packed", date: DateTime(2020, 6, 1), done: true), ShipmentStatus(status: "Packed", date: DateTime(2020, 6, 1), done: true),
ShipmentStatus(status: "Shipped", date: DateTime(2020, 6, 5), done: false), ShipmentStatus(status: "Shipped", date: DateTime(2020, 6, 5), done: false),
@@ -56,10 +58,15 @@ class CartonModel extends BaseModel {
}); });
} }
List<String> cartonTypes = [carton_from_packages, carton_mix_box]; List<String> cartonTypes = [
carton_from_packages,
carton_from_cargos,
carton_mix_box
];
List<String> mixBoxTypes = [mix_delivery, mix_pickup]; List<String> mixBoxTypes = [mix_delivery, mix_pickup];
List<String> cartonTypesInfo = [ List<String> cartonTypesInfo = [
carton_from_packages, carton_from_packages,
carton_from_cargos,
carton_mix_box, carton_mix_box,
carton_from_shipments, carton_from_shipments,
carton_small_bag carton_small_bag
@@ -75,6 +82,7 @@ class CartonModel extends BaseModel {
initData() { initData() {
_selectedIndex = 1; _selectedIndex = 1;
_loadBoxes(); _loadBoxes();
_loadCartonForMixBox();
if (_delivered != null) _delivered.close(); if (_delivered != null) _delivered.close();
_delivered = _getDelivered(); _delivered = _getDelivered();
@@ -108,6 +116,35 @@ class CartonModel extends BaseModel {
} }
} }
Future<void> _loadCartonForMixBox() async {
if (user == null || !user.hasCarton()) return;
String path = "/$cartons_collection/";
if (cartonListener != null) cartonListener.cancel();
cartons = [];
try {
cartonListener = Firestore.instance
.collection("$path")
.where("carton_type",
whereIn: [carton_from_packages, carton_from_cargos])
.where("status", isEqualTo: carton_packed_status)
.where("is_deleted", isEqualTo: false)
.orderBy("user_name")
.snapshots()
.listen((QuerySnapshot snapshot) {
cartons.clear();
cartons = snapshot.documents.map((documentSnapshot) {
var s = Carton.fromMap(
documentSnapshot.data, documentSnapshot.documentID);
return s;
}).toList();
notifyListeners();
});
} catch (e) {
log.warning("Error!! $e");
}
}
Paginator _getDelivered() { Paginator _getDelivered() {
if (user == null || !user.hasCarton()) return null; if (user == null || !user.hasCarton()) return null;
@@ -145,8 +182,10 @@ class CartonModel extends BaseModel {
@override @override
logout() async { logout() async {
if (listener != null) await listener.cancel(); if (listener != null) await listener.cancel();
if (cartonListener != null) await cartonListener.cancel();
if (_delivered != null) _delivered.close(); if (_delivered != null) _delivered.close();
_boxes = []; _boxes = [];
cartons = [];
} }
Future<List<Carton>> getCartons(String shipmentID) async { Future<List<Carton>> getCartons(String shipmentID) async {
@@ -220,38 +259,14 @@ class CartonModel extends BaseModel {
} }
Future<List<Carton>> searchCarton(String term) async { Future<List<Carton>> searchCarton(String term) async {
if (term == null || term == '') return List(); return Services.instance.cartonService.searchCarton(term);
}
List<Carton> _cartons = []; Future<Carton> createMixCarton(Carton carton) {
// return Services.instance.cartonService.createCarton(carton);
}
try { Future<void> updateMixCarton(Carton carton) {
_cartons = [ // return Services.instance.cartonService.updateCarton(carton);
Carton(
cartonNumber: "A100B-1#1",
cargoTypes: [CargoType(name: "General", weight: 12)],
userName: "Seven 7"),
Carton(
cartonNumber: "A100B-1#2",
cargoTypes: [CargoType(name: "General", weight: 12)],
userName: "Seven 7"),
Carton(
cartonNumber: "A100B-1#3",
cargoTypes: [CargoType(name: "General", weight: 12)],
userName: "Seven 7"),
Carton(
cartonNumber: "A100B-1#4",
cargoTypes: [CargoType(name: "General", weight: 12)],
userName: "Seven 7"),
Carton(
cartonNumber: "A100B-1#5",
cargoTypes: [CargoType(name: "General", weight: 12)],
userName: "Seven 7"),
];
} catch (e) {
// permission error
log.warning("user error:" + e.toString());
return null;
}
return _cartons;
} }
} }

View File

@@ -1,3 +1,4 @@
import 'package:fcs/domain/constants.dart';
import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/carton_size.dart'; import 'package:fcs/domain/entities/carton_size.dart';
@@ -46,6 +47,8 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
List<DeliveryAddress> _deliveryAddresses = []; List<DeliveryAddress> _deliveryAddresses = [];
List<CargoType> _cargoTypes = []; List<CargoType> _cargoTypes = [];
CartonSize selectedCatonSize; CartonSize selectedCatonSize;
bool isFromPackages;
bool isFromCargos;
@override @override
void initState() { void initState() {
@@ -55,6 +58,8 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
_load() { _load() {
_carton = widget.carton; _carton = widget.carton;
isFromPackages = _carton.cartonType == carton_from_packages;
isFromCargos = _carton.cartonType == carton_from_cargos;
_getDeliverAddresses(); _getDeliverAddresses();
if (widget.isNew) { if (widget.isNew) {
_lengthCtl.text = "0"; _lengthCtl.text = "0";
@@ -73,8 +78,10 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
_getDeliverAddresses() async { _getDeliverAddresses() async {
var addressModel = var addressModel =
Provider.of<DeliveryAddressModel>(context, listen: false); Provider.of<DeliveryAddressModel>(context, listen: false);
this._deliveryAddresses =
await addressModel.getDeliveryAddresses(_carton.userID); this._deliveryAddresses = isFromPackages
? await addressModel.getDeliveryAddresses(_carton.userID)
: await addressModel.getDeliveryAddresses(_carton.receiverID);
} }
_getCartonSize() { _getCartonSize() {
@@ -321,9 +328,21 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
carton.id = _carton.id; carton.id = _carton.id;
carton.cartonType = _carton.cartonType; carton.cartonType = _carton.cartonType;
carton.fcsShipmentID = _carton.fcsShipmentID; carton.fcsShipmentID = _carton.fcsShipmentID;
carton.userID = _carton.userID;
carton.cargoTypes = _cargoTypes; carton.cargoTypes = _cargoTypes;
carton.packages = _carton.packages.where((e) => e.isChecked).toList(); if (isFromPackages) {
carton.userID = _carton.userID;
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
}
if (isFromCargos) {
carton.receiverID = _carton.receiverID;
carton.receiverFCSID = _carton.receiverFCSID;
carton.receiverName = _carton.receiverName;
carton.senderID = _carton.senderID;
carton.senderFCSID = _carton.senderFCSID;
carton.senderName = _carton.senderName;
}
carton.length = l; carton.length = l;
carton.width = w; carton.width = w;
carton.height = h; carton.height = h;

View File

@@ -1,8 +1,11 @@
import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/helpers/theme.dart'; import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/carton/model/carton_model.dart'; import 'package:fcs/pages/carton/model/carton_model.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/widgets/barcode_scanner.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart'; import 'package:flutter_icons/flutter_icons.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'carton_list_row.dart'; import 'carton_list_row.dart';
@@ -21,7 +24,7 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
PartSearchDelegate({this.callbackCartonSelect}); PartSearchDelegate({this.callbackCartonSelect});
@override @override
String get searchFieldLabel => 'Search by Carton Number/Customer Name'; String get searchFieldLabel => 'Search by Carton Number';
@override @override
ThemeData appBarTheme(BuildContext context) { ThemeData appBarTheme(BuildContext context) {
@@ -40,6 +43,11 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
@override @override
List<Widget> buildActions(BuildContext context) { List<Widget> buildActions(BuildContext context) {
return [ return [
IconButton(
icon: Icon(MaterialCommunityIcons.barcode_scan,
size: 30, color: Colors.white),
onPressed: () => _scan(context),
),
IconButton( IconButton(
icon: Icon(Icons.clear), icon: Icon(Icons.clear),
onPressed: () => query = '', onPressed: () => query = '',
@@ -106,17 +114,41 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
@override @override
Widget buildSuggestions(BuildContext context) { Widget buildSuggestions(BuildContext context) {
final cartonModel = Provider.of<CartonModel>(context);
return Container( return Container(
child: Center( padding: EdgeInsets.only(top: 5),
child: Opacity( child: ListView(
opacity: 0.2, children: cartonModel.cartons
child: Icon( .map((u) => CartonListRow(
MaterialCommunityIcons.package, carton: u,
color: primaryColor, callbackCartonSelect: callbackCartonSelect,
size: 200, ))
), .toList(),
),
), ),
); );
} }
_scan(BuildContext context) async {
PermissionStatus permission =
await PermissionHandler().checkPermissionStatus(PermissionGroup.camera);
if (permission != PermissionStatus.granted) {
Map<PermissionGroup, PermissionStatus> permissions =
await PermissionHandler()
.requestPermissions([PermissionGroup.camera]);
if (permissions[PermissionGroup.camera] != PermissionStatus.granted) {
showMsgDialog(context, "Error", "Camera permission is not granted");
return null;
}
}
try {
String barcode = await scanBarcode();
if (barcode != null) {
query = barcode;
showResults(context);
}
} catch (e) {
print('error: $e');
}
}
} }

View File

@@ -7,9 +7,8 @@ import 'local_text.dart';
class DialogInput extends StatefulWidget { class DialogInput extends StatefulWidget {
final String value; final String value;
final String label; final String label;
final bool isQty;
const DialogInput({Key key, this.label, this.value, this.isQty = false}) const DialogInput({Key key, this.label, this.value}) : super(key: key);
: super(key: key);
@override @override
_DialogInputState createState() => _DialogInputState(); _DialogInputState createState() => _DialogInputState();
} }
@@ -50,7 +49,7 @@ class _DialogInputState extends State<DialogInput> {
key: _formKey, key: _formKey,
child: TextField( child: TextField(
controller: _controller, controller: _controller,
focusNode: widget.isQty ? _focusNode : FocusNode(), focusNode: _focusNode,
autofocus: true, autofocus: true,
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
decoration: new InputDecoration( decoration: new InputDecoration(