update carton

This commit is contained in:
Thinzar Win
2021-01-11 19:35:26 +06:30
parent 8a813023f4
commit db07e01f85
19 changed files with 211 additions and 137 deletions

View File

@@ -301,6 +301,7 @@
"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", "box.selection":"Carton Selection",
"box.weight":"Weight",
"Boxes End ================================================================":"", "Boxes End ================================================================":"",
"Delivery Start ================================================================":"", "Delivery Start ================================================================":"",

View File

@@ -301,6 +301,7 @@
"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":"သေတ္တာ ရွေးချယ်ခြင်း", "box.selection":"သေတ္တာ ရွေးချယ်ခြင်း",
"box.weight":"အလေးချိန်",
"Boxes End ================================================================":"", "Boxes End ================================================================":"",
"Delivery Start ================================================================":"", "Delivery Start ================================================================":"",

View File

@@ -49,7 +49,7 @@ class CartonDataProvider {
.collection(path) .collection(path)
.where("carton_number", isEqualTo: term) .where("carton_number", isEqualTo: term)
.where("carton_type", .where("carton_type",
whereIn: [carton_from_packages, carton_from_cargos]) whereIn: [carton_from_packages, carton_from_cartons])
.where("status", isEqualTo: carton_packed_status) .where("status", isEqualTo: carton_packed_status)
.where("is_deleted", isEqualTo: false) .where("is_deleted", isEqualTo: false)
.orderBy("user_name") .orderBy("user_name")

View File

@@ -78,7 +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_cartons="From cartons";
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

@@ -40,6 +40,7 @@ class Carton {
String mixCartonNumber; String mixCartonNumber;
String cartonSizeID; String cartonSizeID;
String cartonSizeName; String cartonSizeName;
double cartonWeight;
int rate; int rate;
int weight; int weight;
@@ -174,7 +175,8 @@ class Carton {
this.cartonSizeName, this.cartonSizeName,
this.mixBoxType, this.mixBoxType,
this.mixCartons, this.mixCartons,
this.mixCartonIDs}); this.mixCartonIDs,
this.cartonWeight});
Map<String, dynamic> toMap() { Map<String, dynamic> toMap() {
List _cargoTypes = cargoTypes?.map((c) => c.toMap())?.toList() ?? []; List _cargoTypes = cargoTypes?.map((c) => c.toMap())?.toList() ?? [];
@@ -249,6 +251,7 @@ class Carton {
senderFCSID: map['sender_fcs_id'], senderFCSID: map['sender_fcs_id'],
senderName: map['sender_name'], senderName: map['sender_name'],
mixCartonIDs: List<String>.from(map['mix_carton_ids'] ?? []), mixCartonIDs: List<String>.from(map['mix_carton_ids'] ?? []),
cartonWeight: (map['carton_weight'] ?? 0).toDouble(),
); );
} }

View File

@@ -51,7 +51,6 @@ class _CartonEditorState extends State<CartonEditor> {
TextEditingController _widthController = new TextEditingController(); TextEditingController _widthController = new TextEditingController();
TextEditingController _heightController = new TextEditingController(); TextEditingController _heightController = new TextEditingController();
TextEditingController _lengthController = new TextEditingController(); TextEditingController _lengthController = new TextEditingController();
List<DeliveryAddress> _deliveryAddresses = [];
DeliveryAddress _deliveryAddress = new DeliveryAddress(); DeliveryAddress _deliveryAddress = new DeliveryAddress();
List<CargoType> _cargoTypes = []; List<CargoType> _cargoTypes = [];
@@ -116,7 +115,6 @@ class _CartonEditorState extends State<CartonEditor> {
if (isFromPackages) _loadPackages(); if (isFromPackages) _loadPackages();
if (!isMixBox) { if (!isMixBox) {
_getDeliverAddresses();
_getCartonSize(); _getCartonSize();
} }
} else { } else {
@@ -203,15 +201,6 @@ class _CartonEditorState extends State<CartonEditor> {
}); });
} }
_getDeliverAddresses() async {
var addressModel =
Provider.of<DeliveryAddressModel>(context, listen: false);
bool isFromPackages = _carton.cartonType == carton_from_packages;
this._deliveryAddresses = isFromPackages
? await addressModel.getDeliveryAddresses(_carton.userID)
: await addressModel.getDeliveryAddresses(_carton.receiverID);
}
_getCartonSize() { _getCartonSize() {
var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false); var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false);
cartonSizeModel.cartonSizes.forEach((c) { cartonSizeModel.cartonSizes.forEach((c) {
@@ -237,7 +226,7 @@ class _CartonEditorState extends State<CartonEditor> {
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 isFromPackages = _selectedCartonType == carton_from_packages;
bool isFromCargos = _selectedCartonType == carton_from_cargos; bool isFromCartons = _selectedCartonType == carton_from_cartons;
bool isMixBox = _selectedCartonType == carton_mix_box; bool isMixBox = _selectedCartonType == carton_mix_box;
final shipmentBox = DisplayText( final shipmentBox = DisplayText(
@@ -603,7 +592,7 @@ class _CartonEditorState extends State<CartonEditor> {
}, },
) )
: Container(), : Container(),
isFromCargos isFromCartons
? Container( ? Container(
padding: const EdgeInsets.only(top: 15), padding: const EdgeInsets.only(top: 15),
child: Row( child: Row(
@@ -646,8 +635,14 @@ class _CartonEditorState extends State<CartonEditor> {
builder: (context) => builder: (context) =>
DeliveryAddressSelection( DeliveryAddressSelection(
deliveryAddress: _deliveryAddress, deliveryAddress: _deliveryAddress,
deliveryAddresses: user: isFromPackages
_deliveryAddresses)), ? User(
id: _carton.userID,
name: _carton.userName)
: User(
id: _carton.receiverID,
name: _carton
.receiverName))),
); );
if (d == null) return; if (d == null) return;
setState(() { setState(() {
@@ -658,7 +653,7 @@ class _CartonEditorState extends State<CartonEditor> {
SizedBox( SizedBox(
height: 20, height: 20,
), ),
isFromPackages || isFromCargos isFromPackages || isFromCartons
? _isNew ? _isNew
? createBtn ? createBtn
: saveBtn : saveBtn
@@ -679,7 +674,7 @@ class _CartonEditorState extends State<CartonEditor> {
return InkWell( return InkWell(
onTap: () async { onTap: () async {
bool isFromPackages = _selectedCartonType == carton_from_packages; bool isFromPackages = _selectedCartonType == carton_from_packages;
bool isFromCargos = _selectedCartonType == carton_from_cargos; bool isFromCartons = _selectedCartonType == carton_from_cartons;
if (isFromPackages) { if (isFromPackages) {
_loadPackages(); _loadPackages();
c.value.packages = _carton.packages; c.value.packages = _carton.packages;
@@ -812,7 +807,7 @@ 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; bool isFromCartons = _selectedCartonType == carton_from_cartons;
if (_fcsShipment == null && _isNew) { if (_fcsShipment == null && _isNew) {
showMsgDialog(context, "Error", "Please select FCS shipment"); showMsgDialog(context, "Error", "Please select FCS shipment");
@@ -824,12 +819,12 @@ class _CartonEditorState extends State<CartonEditor> {
return; return;
} }
if (consignee == null && isFromCargos) { if (consignee == null && isFromCartons) {
showMsgDialog(context, "Error", "Please select consignee's FCS ID"); showMsgDialog(context, "Error", "Please select consignee's FCS ID");
return; return;
} }
if (sender == null && isFromCargos) { if (sender == null && isFromCartons) {
showMsgDialog(context, "Error", "Please select sender's FCS ID"); showMsgDialog(context, "Error", "Please select sender's FCS ID");
return; return;
} }
@@ -849,7 +844,7 @@ class _CartonEditorState extends State<CartonEditor> {
carton.packages = _carton.packages.where((e) => e.isChecked).toList(); carton.packages = _carton.packages.where((e) => e.isChecked).toList();
} }
if (isFromCargos) { if (isFromCartons) {
carton.receiverID = consignee?.id; carton.receiverID = consignee?.id;
carton.receiverFCSID = consignee?.fcsID; carton.receiverFCSID = consignee?.fcsID;
carton.receiverName = consignee?.name; carton.receiverName = consignee?.name;
@@ -881,7 +876,7 @@ class _CartonEditorState extends State<CartonEditor> {
_cartons.add(_carton); _cartons.add(_carton);
} }
if (isFromCargos) { if (isFromCartons) {
_cartonsForCargos.add(_carton); _cartonsForCargos.add(_carton);
} }
@@ -943,7 +938,7 @@ class _CartonEditorState extends State<CartonEditor> {
_save() async { _save() async {
bool isFromPackages = _selectedCartonType == carton_from_packages; bool isFromPackages = _selectedCartonType == carton_from_packages;
bool isFromCargos = _selectedCartonType == carton_from_cargos; bool isFromCargos = _selectedCartonType == carton_from_cartons;
if ((_cargoTypes?.length ?? 0) == 0 && (isFromPackages || isFromCargos)) { 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;

View File

@@ -88,7 +88,7 @@ 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;
isFromCartons = _box.cartonType == carton_from_cargos; isFromCartons = _box.cartonType == carton_from_cartons;
isEdiable = (isFromPackages || isMixBox || isFromCartons) && isEdiable = (isFromPackages || isMixBox || isFromCartons) &&
_box.status == carton_packed_status; _box.status == carton_packed_status;
@@ -410,7 +410,7 @@ class _CartonInfoState extends State<CartonInfo> {
} }
_gotoEditor() async { _gotoEditor() async {
widget.box.mixCartons=_box.mixCartons; widget.box.mixCartons = _box.mixCartons;
bool updated = await Navigator.push<bool>( bool updated = await Navigator.push<bool>(
context, context,
CupertinoPageRoute(builder: (context) => CartonEditor(box: widget.box)), CupertinoPageRoute(builder: (context) => CartonEditor(box: widget.box)),

View File

@@ -78,7 +78,7 @@ class CartonListRow extends StatelessWidget {
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
new Text( new Text(
"${box.actualWeight?.toStringAsFixed(2) ?? ''} lb", "${box.cartonWeight?.toStringAsFixed(2) ?? ''} lb",
style: style:
new TextStyle(fontSize: 15.0, color: Colors.grey), new TextStyle(fontSize: 15.0, color: Colors.grey),
), ),

View File

@@ -9,17 +9,20 @@ import 'package:fcs/domain/vo/message.dart';
import 'package:fcs/domain/vo/shipment_status.dart'; import 'package:fcs/domain/vo/shipment_status.dart';
import 'package:fcs/helpers/paginator.dart'; import 'package:fcs/helpers/paginator.dart';
import 'package:fcs/pages/main/model/base_model.dart'; import 'package:fcs/pages/main/model/base_model.dart';
import 'package:fcs/pagination/paginator_listener.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
class CartonModel extends BaseModel { class CartonModel extends BaseModel {
List<Carton> _boxes = []; List<Carton> _boxes = [];
List<Carton> cartons = []; PaginatorListener cartonsByFilter;
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);
Paginator _delivered; Paginator _delivered;
int _selectedIndex = 1; int _selectedIndex = 1;
int _selectedIndexFilter = 1;
bool isLoading = false; bool isLoading = false;
StreamSubscription<QuerySnapshot> listener; StreamSubscription<QuerySnapshot> listener;
@@ -60,13 +63,13 @@ class CartonModel extends BaseModel {
List<String> cartonTypes = [ List<String> cartonTypes = [
carton_from_packages, carton_from_packages,
// carton_from_cargos, carton_from_cartons,
carton_mix_box 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_from_cartons,
carton_mix_box, carton_mix_box,
carton_from_shipments, carton_from_shipments,
carton_small_bag carton_small_bag
@@ -77,18 +80,45 @@ class CartonModel extends BaseModel {
notifyListeners(); notifyListeners();
} }
get selectedIndex => _selectedIndex; set selectedIndexFilter(int index) {
_selectedIndexFilter = index;
_loadCartonsByFilter(
_selectedIndexFilter == 1 ? "carton_weight" : "user_name");
notifyListeners();
}
initData() { get selectedIndex => _selectedIndex;
get selectedIndexFilter => _selectedIndexFilter;
initData() async {
_selectedIndex = 1; _selectedIndex = 1;
_selectedIndexFilter = 1;
_loadBoxes(); _loadBoxes();
_loadCartonForMixBox();
if (_delivered != null) _delivered.close(); if (_delivered != null) _delivered.close();
_delivered = _getDelivered(); _delivered = _getDelivered();
_delivered.load(); _delivered.load();
} }
@override
void privilegeChanged() {
if (user != null || !user.hasCarton()) {
_initData();
}
}
Future<void> _initData() async {
logout();
_selectedIndexFilter = 1;
cartonsByFilter = PaginatorListener<Carton>(
(data, id) => Carton.fromMap(data, id), onChange: () {
notifyListeners();
}, rowPerLoad: 30, insertNewByListener: true);
_loadCartonsByFilter(
_selectedIndexFilter == 1 ? "carton_weight" : "user_name");
}
Future<void> _loadBoxes() async { Future<void> _loadBoxes() async {
if (user == null || !user.hasCarton()) return; if (user == null || !user.hasCarton()) return;
String path = "/$cartons_collection/"; String path = "/$cartons_collection/";
@@ -116,30 +146,27 @@ class CartonModel extends BaseModel {
} }
} }
Future<void> _loadCartonForMixBox() async { Future<void> _loadCartonsByFilter(String orderName) async {
if (user == null || !user.hasCarton()) return; if (user == null || !user.hasCarton()) return null;
String path = "/$cartons_collection/"; String path = "/$cartons_collection";
if (cartonListener != null) cartonListener.cancel();
cartons = [];
try { try {
cartonListener = Firestore.instance Query listenerQuery = Firestore.instance
.collection("$path") .collection("$path")
.where("carton_type", .where("carton_type",
whereIn: [carton_from_packages, carton_from_cargos]) whereIn: [carton_from_packages, carton_from_cartons])
.where("status", isEqualTo: carton_packed_status) .where("status", isEqualTo: carton_packed_status)
.where("is_deleted", isEqualTo: false) .orderBy(orderName, descending: true);
.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(); Query pageQuery = Firestore.instance
}); .collection("$path")
.where("carton_type",
whereIn: [carton_from_packages, carton_from_cartons])
.where("status", isEqualTo: carton_packed_status)
.orderBy(orderName, descending: true);
cartonsByFilter.refresh(
listeningQuery: listenerQuery, pageQuery: pageQuery);
} catch (e) { } catch (e) {
log.warning("Error!! $e"); log.warning("Error!! $e");
} }
@@ -184,8 +211,8 @@ class CartonModel extends BaseModel {
if (listener != null) await listener.cancel(); if (listener != null) await listener.cancel();
if (cartonListener != null) await cartonListener.cancel(); if (cartonListener != null) await cartonListener.cancel();
if (_delivered != null) _delivered.close(); if (_delivered != null) _delivered.close();
if (cartonsByFilter != null) cartonsByFilter.close();
_boxes = []; _boxes = [];
cartons = [];
} }
Future<List<Carton>> getCartons(String shipmentID) async { Future<List<Carton>> getCartons(String shipmentID) async {
@@ -261,5 +288,4 @@ class CartonModel extends BaseModel {
Future<List<Carton>> searchCarton(String term) async { Future<List<Carton>> searchCarton(String term) async {
return Services.instance.cartonService.searchCarton(term); return Services.instance.cartonService.searchCarton(term);
} }
} }

View File

@@ -46,11 +46,10 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
Carton _carton; Carton _carton;
bool _isLoading = false; bool _isLoading = false;
DeliveryAddress _deliveryAddress = new DeliveryAddress(); DeliveryAddress _deliveryAddress = new DeliveryAddress();
List<DeliveryAddress> _deliveryAddresses = [];
List<CargoType> _cargoTypes = []; List<CargoType> _cargoTypes = [];
CartonSize selectedCatonSize; CartonSize selectedCatonSize;
bool isFromPackages; bool isFromPackages;
bool isFromCargos; bool isFromCartons;
@override @override
void initState() { void initState() {
@@ -61,8 +60,8 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
_load() { _load() {
_carton = widget.carton; _carton = widget.carton;
isFromPackages = _carton.cartonType == carton_from_packages; isFromPackages = _carton.cartonType == carton_from_packages;
isFromCargos = _carton.cartonType == carton_from_cargos; isFromCartons = _carton.cartonType == carton_from_cartons;
_getDeliverAddresses();
if (widget.isNew) { if (widget.isNew) {
_lengthCtl.text = "0"; _lengthCtl.text = "0";
_widthCtl.text = "0"; _widthCtl.text = "0";
@@ -77,18 +76,6 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
} }
} }
_getDeliverAddresses() async {
var addressModel =
Provider.of<DeliveryAddressModel>(context, listen: false);
var deliveryAddresses = isFromPackages
? await addressModel.getDeliveryAddresses(_carton.userID)
: await addressModel.getDeliveryAddresses(_carton.receiverID);
setState(() {
this._deliveryAddresses = deliveryAddresses;
});
}
_getCartonSize() { _getCartonSize() {
var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false); var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false);
cartonSizeModel.cartonSizes.forEach((c) { cartonSizeModel.cartonSizes.forEach((c) {
@@ -205,9 +192,13 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
CupertinoPageRoute( CupertinoPageRoute(
builder: (context) => DeliveryAddressSelection( builder: (context) => DeliveryAddressSelection(
deliveryAddress: _deliveryAddress, deliveryAddress: _deliveryAddress,
deliveryAddresses: this._deliveryAddresses, user: isFromPackages
user: widget.consignee, ? User(
onAdded: () => _getDeliverAddresses(), id: _carton.userID,
name: _carton.userName)
: User(
id: _carton.receiverID,
name: _carton.receiverName),
)), )),
); );
if (d == null) return; if (d == null) return;
@@ -342,7 +333,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
carton.packages = _carton.packages.where((e) => e.isChecked).toList(); carton.packages = _carton.packages.where((e) => e.isChecked).toList();
} }
if (isFromCargos) { if (isFromCartons) {
carton.receiverID = _carton.receiverID; carton.receiverID = _carton.receiverID;
carton.receiverFCSID = _carton.receiverFCSID; carton.receiverFCSID = _carton.receiverFCSID;
carton.receiverName = _carton.receiverName; carton.receiverName = _carton.receiverName;

View File

@@ -8,7 +8,11 @@ import 'carton_search.dart';
class CartonListRow extends StatefulWidget { class CartonListRow extends StatefulWidget {
final CallbackCartonSelect callbackCartonSelect; final CallbackCartonSelect callbackCartonSelect;
final Carton carton; final Carton carton;
const CartonListRow({this.carton, this.callbackCartonSelect});
// const CartonListRow({this.carton, this.callbackCartonSelect});
CartonListRow(
{Key key, this.carton, this.callbackCartonSelect})
: super(key: key);
@override @override
_CartonListRowState createState() => _CartonListRowState(); _CartonListRowState createState() => _CartonListRowState();
@@ -82,7 +86,7 @@ class _CartonListRowState extends State<CartonListRow> {
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
new Text( new Text(
"${_carton.actualWeight?.toStringAsFixed(2) ?? ''} lb", "${_carton.cartonWeight?.toStringAsFixed(2) ?? ''} lb",
style: new TextStyle( style: new TextStyle(
fontSize: 15.0, color: Colors.grey), fontSize: 15.0, color: Colors.grey),
), ),

View File

@@ -1,8 +1,14 @@
import 'package:fcs/domain/constants.dart';
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/main/util.dart';
import 'package:fcs/pages/widgets/barcode_scanner.dart'; import 'package:fcs/pages/widgets/barcode_scanner.dart';
import 'package:fcs/pages/widgets/local_popup_menu_button.dart';
import 'package:fcs/pages/widgets/local_popupmenu.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/popupmenu.dart';
import 'package:fcs/pagination/paginator_listview.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:permission_handler/permission_handler.dart';
@@ -42,12 +48,32 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
@override @override
List<Widget> buildActions(BuildContext context) { List<Widget> buildActions(BuildContext context) {
var boxModel = Provider.of<CartonModel>(context);
final popupMenu =
StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
return LocalPopupMenuButton(
popmenus: [
LocalPopupMenu(
id: 1,
textKey: "box.weight",
selected: boxModel.selectedIndexFilter == 1),
LocalPopupMenu(
id: 2,
textKey: "box.name",
selected: boxModel.selectedIndexFilter == 2)
],
popupMenuCallback: (p) => setState(() {
boxModel.selectedIndexFilter = p.id;
}));
});
return [ return [
IconButton( IconButton(
icon: Icon(MaterialCommunityIcons.barcode_scan, icon: Icon(MaterialCommunityIcons.barcode_scan,
size: 30, color: Colors.white), size: 30, color: Colors.white),
onPressed: () => _scan(context), onPressed: () => _scan(context),
), ),
popupMenu,
IconButton( IconButton(
icon: Icon(Icons.clear), icon: Icon(Icons.clear),
onPressed: () => query = '', onPressed: () => query = '',
@@ -85,6 +111,7 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
child: ListView( child: ListView(
children: snapshot.data children: snapshot.data
.map((u) => CartonListRow( .map((u) => CartonListRow(
key: ValueKey(u.id),
carton: u, carton: u,
callbackCartonSelect: callbackCartonSelect, callbackCartonSelect: callbackCartonSelect,
)) ))
@@ -115,15 +142,17 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
@override @override
Widget buildSuggestions(BuildContext context) { Widget buildSuggestions(BuildContext context) {
final cartonModel = Provider.of<CartonModel>(context); final cartonModel = Provider.of<CartonModel>(context);
return Container( return Container(
padding: EdgeInsets.only(top: 5), padding: EdgeInsets.only(top: 5),
child: ListView( child: PaginatorListView<Carton>(
children: cartonModel.cartons paginatorListener: cartonModel.cartonsByFilter,
.map((u) => CartonListRow( rowBuilder: (c) => CartonListRow(
carton: u, key: ValueKey(c.id),
carton: c,
callbackCartonSelect: callbackCartonSelect, callbackCartonSelect: callbackCartonSelect,
)) ),
.toList(), color: primaryColor,
), ),
); );
} }

View File

@@ -207,7 +207,7 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
Provider.of<DeliveryAddressModel>(context, listen: false); Provider.of<DeliveryAddressModel>(context, listen: false);
try { try {
await deliveryAddressModel.createDeliveryAddress(deliveryAddress); await deliveryAddressModel.createDeliveryAddress(deliveryAddress);
Navigator.pop(context,true); Navigator.pop(context, true);
} catch (e) { } catch (e) {
showMsgDialog(context, "Error", e.toString()); showMsgDialog(context, "Error", e.toString());
} finally { } finally {
@@ -223,6 +223,9 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
if (!valid) { if (!valid) {
return; return;
} }
if (widget.user != null) {
deliveryAddress.userID = widget.user.id;
}
setState(() { setState(() {
_isLoading = true; _isLoading = true;
}); });
@@ -230,7 +233,7 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
Provider.of<DeliveryAddressModel>(context, listen: false); Provider.of<DeliveryAddressModel>(context, listen: false);
try { try {
await deliveryAddressModel.updateDeliveryAddress(deliveryAddress); await deliveryAddressModel.updateDeliveryAddress(deliveryAddress);
Navigator.pop(context,true); Navigator.pop(context, true);
} catch (e) { } catch (e) {
showMsgDialog(context, "Error", e.toString()); showMsgDialog(context, "Error", e.toString());
} finally { } finally {
@@ -251,8 +254,11 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
try { try {
DeliveryAddressModel deliveryAddressModel = DeliveryAddressModel deliveryAddressModel =
Provider.of<DeliveryAddressModel>(context, listen: false); Provider.of<DeliveryAddressModel>(context, listen: false);
if (widget.user != null) {
_deliveryAddress.userID = widget.user.id;
}
await deliveryAddressModel.deleteDeliveryAddress(_deliveryAddress); await deliveryAddressModel.deleteDeliveryAddress(_deliveryAddress);
Navigator.pop(context,true); Navigator.pop(context, true);
} catch (e) { } catch (e) {
showMsgDialog(context, "Error", e.toString()); showMsgDialog(context, "Error", e.toString());
} finally { } finally {

View File

@@ -91,6 +91,7 @@ class DeliveryAddressModel extends BaseModel {
.collection('users') .collection('users')
.document("$userID") .document("$userID")
.collection("$path") .collection("$path")
.orderBy("full_name")
.getDocuments(); .getDocuments();
return querySnap.documents return querySnap.documents
.map((e) => DeliveryAddress.fromMap(e.data, e.documentID)) .map((e) => DeliveryAddress.fromMap(e.data, e.documentID))

View File

@@ -70,7 +70,7 @@ class _PackageInfoState extends State<PackageInfo> {
bool canChangeDeliveryAddress = bool canChangeDeliveryAddress =
_package?.status == package_received_status || _package?.status == package_received_status ||
_package?.status == package_processed_status; _package?.status == package_processed_status;
var deliveryAddressModel = Provider.of<DeliveryAddressModel>(context); var mainModel = Provider.of<MainModel>(context);
final trackingIdBox = DisplayText( final trackingIdBox = DisplayText(
text: _package?.trackingID ?? "", text: _package?.trackingID ?? "",
@@ -122,7 +122,7 @@ class _PackageInfoState extends State<PackageInfo> {
CupertinoPageRoute( CupertinoPageRoute(
builder: (context) => DeliveryAddressSelection( builder: (context) => DeliveryAddressSelection(
deliveryAddress: _package.deliveryAddress, deliveryAddress: _package.deliveryAddress,
deliveryAddresses: deliveryAddressModel.deliveryAddresses)), user: mainModel.user)),
); );
if (d == null) return; if (d == null) return;
_changeDeliverayAddress(d); _changeDeliverayAddress(d);

View File

@@ -4,6 +4,7 @@ import 'package:fcs/domain/vo/delivery_address.dart';
import 'package:fcs/helpers/theme.dart'; import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/carton/cargo_type_editor.dart'; import 'package:fcs/pages/carton/cargo_type_editor.dart';
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart'; import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
import 'package:fcs/pages/main/model/main_model.dart';
import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
import 'package:fcs/pages/widgets/defalut_delivery_address.dart'; import 'package:fcs/pages/widgets/defalut_delivery_address.dart';
import 'package:fcs/pages/widgets/delivery_address_selection.dart'; import 'package:fcs/pages/widgets/delivery_address_selection.dart';
@@ -81,7 +82,8 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var deliveryAddressModel = Provider.of<DeliveryAddressModel>(context); var mainModel = Provider.of<MainModel>(context);
final shipmentWeightBox = DisplayText( final shipmentWeightBox = DisplayText(
labelTextKey: "shipment.box.shipment.weight", labelTextKey: "shipment.box.shipment.weight",
text: shipmentWeight == null ? "" : shipmentWeight.toStringAsFixed(0), text: shipmentWeight == null ? "" : shipmentWeight.toStringAsFixed(0),
@@ -192,8 +194,7 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
CupertinoPageRoute( CupertinoPageRoute(
builder: (context) => DeliveryAddressSelection( builder: (context) => DeliveryAddressSelection(
deliveryAddress: _box.deliveryAddress, deliveryAddress: _box.deliveryAddress,
deliveryAddresses: user: mainModel.user)),
deliveryAddressModel.deliveryAddresses)),
); );
if (d == null) return; if (d == null) return;
setState(() { setState(() {

View File

@@ -130,8 +130,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
CupertinoPageRoute( CupertinoPageRoute(
builder: (context) => DeliveryAddressSelection( builder: (context) => DeliveryAddressSelection(
deliveryAddress: _shipment.pickupAddress, deliveryAddress: _shipment.pickupAddress,
deliveryAddresses: deliveryAddressModel.deliveryAddresses, user: mainModel.user)),
)),
); );
if (address == null) return; if (address == null) return;
setState(() { setState(() {

View File

@@ -9,34 +9,44 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
typedef OnAdded(); class DeliveryAddressSelection extends StatefulWidget {
class DeliveryAddressSelection extends StatelessWidget {
final DeliveryAddress deliveryAddress; final DeliveryAddress deliveryAddress;
final List<DeliveryAddress> deliveryAddresses;
final User user; final User user;
final OnAdded onAdded;
const DeliveryAddressSelection( const DeliveryAddressSelection({
{Key key, Key key,
this.deliveryAddress, this.deliveryAddress,
this.deliveryAddresses,
this.user, this.user,
this.onAdded}) }) : super(key: key);
: super(key: key);
Future<List<DeliveryAddress>> _getDeliverAddresses( @override
BuildContext context) async { _DeliveryAddressSelectionState createState() =>
_DeliveryAddressSelectionState();
}
class _DeliveryAddressSelectionState extends State<DeliveryAddressSelection> {
List<DeliveryAddress> _deliveryAddresses = [];
@override
void initState() {
_getDeliverAddresses();
super.initState();
}
_getDeliverAddresses() async {
var addressModel = var addressModel =
Provider.of<DeliveryAddressModel>(context, listen: false); Provider.of<DeliveryAddressModel>(context, listen: false);
var _deliveryAddresses = await addressModel.getDeliveryAddresses(user.id); var deliveryAddresses =
return _deliveryAddresses; await addressModel.getDeliveryAddresses(widget.user.id);
setState(() {
this._deliveryAddresses = deliveryAddresses;
});
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (user != null) {} if (widget.user != null) {}
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
centerTitle: true, centerTitle: true,
@@ -52,12 +62,10 @@ class DeliveryAddressSelection extends StatelessWidget {
floatingActionButton: FloatingActionButton.extended( floatingActionButton: FloatingActionButton.extended(
onPressed: () async { onPressed: () async {
bool updated = await Navigator.of(context).push(CupertinoPageRoute( bool updated = await Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => DeliveryAddressEditor( builder: (context) =>
user: user, DeliveryAddressEditor(user: widget.user)));
))); if (updated ?? false) {
if (updated && onAdded != null) { _getDeliverAddresses();
onAdded();
Navigator.pop(context);
} }
}, },
icon: Icon(Icons.add), icon: Icon(Icons.add),
@@ -71,37 +79,46 @@ class DeliveryAddressSelection extends StatelessWidget {
separatorBuilder: (c, i) => Divider( separatorBuilder: (c, i) => Divider(
color: primaryColor, color: primaryColor,
), ),
itemCount: deliveryAddresses.length, itemCount: _deliveryAddresses.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
return _row(context, deliveryAddresses[index]); return _row(context, _deliveryAddresses[index]);
}), }),
)); ));
} }
_row(BuildContext context, DeliveryAddress _deliveryAddress) { _row(BuildContext context, DeliveryAddress _deliveryAddress) {
return InkWell( return Row(
onTap: () => _select(context, _deliveryAddress),
child: Row(
children: [ children: [
Padding( InkWell(
onTap: () => _select(context, _deliveryAddress),
child: Padding(
padding: const EdgeInsets.all(10.0), padding: const EdgeInsets.all(10.0),
child: Icon(Icons.check, child: Icon(Icons.check,
color: deliveryAddress != null && color: widget.deliveryAddress != null &&
_deliveryAddress.id == deliveryAddress.id _deliveryAddress.id == widget.deliveryAddress.id
? primaryColor ? primaryColor
: Colors.black26), : Colors.black26),
), ),
),
Expanded( Expanded(
child: DeliveryAddressRow( child: DeliveryAddressRow(
key: ValueKey(_deliveryAddress.id), key: ValueKey(_deliveryAddress.id),
deliveryAddress: _deliveryAddress, deliveryAddress: _deliveryAddress,
)), selectionCallback: (d) => _edit(context, _deliveryAddress))),
], ],
),
); );
} }
_select(BuildContext context, DeliveryAddress _deliveryAddress) { _select(BuildContext context, DeliveryAddress _deliveryAddress) {
Navigator.pop(context, _deliveryAddress); Navigator.pop(context, _deliveryAddress);
} }
_edit(BuildContext context, DeliveryAddress deliveryAddress) async {
bool updated = await Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => DeliveryAddressEditor(
user: widget.user, deliveryAddress: deliveryAddress)));
if (updated ?? false) {
_getDeliverAddresses();
}
}
} }

View File

@@ -51,7 +51,7 @@ class _DialogInputState extends State<DialogInput> {
controller: _controller, controller: _controller,
focusNode: _focusNode, focusNode: _focusNode,
autofocus: true, autofocus: true,
keyboardType: TextInputType.number, keyboardType: TextInputType.numberWithOptions(decimal: true),
decoration: new InputDecoration( decoration: new InputDecoration(
focusedBorder: UnderlineInputBorder( focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0))), borderSide: BorderSide(color: primaryColor, width: 1.0))),