update carton
This commit is contained in:
@@ -10,13 +10,17 @@ import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/carton/carton_package_table.dart';
|
||||
import 'package:fcs/pages/carton_search/carton_search.dart';
|
||||
import 'package:fcs/pages/carton_size/carton_size_list.dart';
|
||||
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
|
||||
import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/package/model/package_model.dart';
|
||||
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
|
||||
import 'package:fcs/pages/user_search/user_serach.dart';
|
||||
import 'package:fcs/pages/widgets/defalut_delivery_address.dart';
|
||||
import 'package:fcs/pages/widgets/delivery_address_selection.dart';
|
||||
import 'package:fcs/pages/widgets/display_text.dart';
|
||||
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
|
||||
import 'package:fcs/pages/widgets/length_picker.dart';
|
||||
import 'package:fcs/pages/widgets/local_button.dart';
|
||||
import 'package:fcs/pages/widgets/local_dropdown.dart';
|
||||
import 'package:fcs/pages/widgets/local_radio_buttons.dart';
|
||||
@@ -27,6 +31,8 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'cargo_type_addtion.dart';
|
||||
import 'carton_cargo_table.dart';
|
||||
import 'carton_list_row.dart';
|
||||
import 'carton_row.dart';
|
||||
import 'mix_carton_editor.dart';
|
||||
@@ -47,6 +53,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
TextEditingController _widthController = new TextEditingController();
|
||||
TextEditingController _heightController = new TextEditingController();
|
||||
TextEditingController _lengthController = new TextEditingController();
|
||||
List<DeliveryAddress> _deliveryAddresses = [];
|
||||
|
||||
Carton _carton;
|
||||
bool _isLoading = false;
|
||||
@@ -62,6 +69,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
Carton _mixCarton;
|
||||
List<Carton> _cartons = [];
|
||||
List<Carton> _mixCartons = [];
|
||||
CartonSize selectedCatonSize;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -85,6 +93,8 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_isNew = false;
|
||||
_user = User(fcsID: _carton.fcsID, name: _carton.userName);
|
||||
_loadPackages();
|
||||
_getDeliverAddresses();
|
||||
getCartonSize();
|
||||
} else {
|
||||
_carton = Carton(
|
||||
cargoTypes: [],
|
||||
@@ -97,12 +107,12 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_selectedCartonType = carton_from_packages;
|
||||
_selectedMixType = mix_delivery;
|
||||
_loadFcsShipments();
|
||||
_cartons = [Carton(cartonNumber: "A100B-1#3", userName: "Seven 7")];
|
||||
// _cartons = [Carton(cartonNumber: "A100B-1#3", userName: "Seven 7")];
|
||||
|
||||
_mixCartons = [
|
||||
Carton(cartonNumber: "A100B-1#1", userName: "Seven 7"),
|
||||
Carton(cartonNumber: "A100B-1#2", userName: "Seven 7"),
|
||||
];
|
||||
// _mixCartons = [
|
||||
// Carton(cartonNumber: "A100B-1#1", userName: "Seven 7"),
|
||||
// Carton(cartonNumber: "A100B-1#2", userName: "Seven 7"),
|
||||
// ];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,19 +162,19 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
setState(() {
|
||||
_carton.packages = packages;
|
||||
});
|
||||
_populateDeliveryAddress();
|
||||
// _populateDeliveryAddress();
|
||||
}
|
||||
|
||||
_populateDeliveryAddress() {
|
||||
if (_carton.packages == null) return;
|
||||
var d = _carton.packages
|
||||
.firstWhere((p) => p.isChecked && p.deliveryAddress != null,
|
||||
orElse: () => null)
|
||||
?.deliveryAddress;
|
||||
setState(() {
|
||||
_deliveryAddress = d;
|
||||
});
|
||||
}
|
||||
// _populateDeliveryAddress() {
|
||||
// if (_carton.packages == null) return;
|
||||
// var d = _carton.packages
|
||||
// .firstWhere((p) => p.isChecked && p.deliveryAddress != null,
|
||||
// orElse: () => null)
|
||||
// ?.deliveryAddress;
|
||||
// setState(() {
|
||||
// _deliveryAddress = d;
|
||||
// });
|
||||
// }
|
||||
|
||||
_calShipmentWeight() {
|
||||
double l = double.parse(_lengthController.text, (s) => 0);
|
||||
@@ -175,6 +185,32 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
});
|
||||
}
|
||||
|
||||
_getDeliverAddresses() async {
|
||||
var addressModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
this._deliveryAddresses =
|
||||
await addressModel.getDeliveryAddresses(_carton.userID);
|
||||
}
|
||||
|
||||
getCartonSize() {
|
||||
var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false);
|
||||
cartonSizeModel.cartonSizes.forEach((c) {
|
||||
if (c.length == _carton.length &&
|
||||
c.width == _carton.width &&
|
||||
c.height == _carton.height) {
|
||||
print(c.name);
|
||||
// setState(() {
|
||||
// // selectedCatonSize = CartonSize(
|
||||
// // id: c.id,
|
||||
// // name: c.name,
|
||||
// // length: c.length,
|
||||
// // width: c.width,
|
||||
// // height: c.height);
|
||||
// });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
@@ -267,7 +303,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
onPressed: () async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
if (_user == null && isFromPackages) {
|
||||
showMsgDialog(context, "Error", "Please select customer");
|
||||
showMsgDialog(context, "Error", "Please select FCS ID");
|
||||
return;
|
||||
}
|
||||
if (_fcsShipment == null && _isNew) {
|
||||
@@ -285,6 +321,8 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
carton.fcsShipmentID =
|
||||
_isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||
carton.userID = _user?.id;
|
||||
carton.fcsID = _user?.fcsID;
|
||||
carton.userName = _user?.name;
|
||||
carton.packages =
|
||||
_carton.packages.where((e) => e.isChecked).toList();
|
||||
|
||||
@@ -298,12 +336,18 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
Navigator.push(
|
||||
Carton _c = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
PackageCartonEditor(carton: carton, isNew: _isNew)),
|
||||
);
|
||||
if (_c == null) return;
|
||||
var cartonModel =
|
||||
Provider.of<CartonModel>(context, listen: false);
|
||||
Carton _carton = await cartonModel.getCarton(_c.id);
|
||||
_cartons.add(_carton);
|
||||
setState(() {});
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
@@ -369,7 +413,59 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
),
|
||||
),
|
||||
);
|
||||
final cargoTableTitleBox = LocalTitle(
|
||||
textKey: "box.cargo.type",
|
||||
trailing: IconButton(
|
||||
icon: Icon(
|
||||
Icons.add_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
List<CargoType> cargos = await Navigator.push<List<CargoType>>(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => CargoTypeAddition()));
|
||||
if (cargos == null) return;
|
||||
setState(() {
|
||||
_carton.cargoTypes.clear();
|
||||
_carton.cargoTypes.addAll(cargos);
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
final cargoTableBox = CargoTable(
|
||||
isNew: _isNew,
|
||||
cargoTypes: _carton.cargoTypes,
|
||||
onAdd: (c) => _addCargo(c),
|
||||
onRemove: (c) => _removeCargo(c),
|
||||
);
|
||||
|
||||
final lengthBox = LengthPicker(
|
||||
controller: _lengthController,
|
||||
lableKey: "box.length",
|
||||
isReadOnly: true,
|
||||
);
|
||||
final widthBox = LengthPicker(
|
||||
controller: _widthController,
|
||||
lableKey: "box.width",
|
||||
isReadOnly: true,
|
||||
);
|
||||
final heightBox = LengthPicker(
|
||||
controller: _heightController,
|
||||
lableKey: "box.height",
|
||||
isReadOnly: true,
|
||||
);
|
||||
final dimBox = Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: Icon(FontAwesome.arrow_circle_right, color: primaryColor),
|
||||
),
|
||||
SizedBox(child: lengthBox, width: 80),
|
||||
SizedBox(child: widthBox, width: 80),
|
||||
SizedBox(child: heightBox, width: 80),
|
||||
],
|
||||
);
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
@@ -432,20 +528,53 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
setState(() {
|
||||
p.isChecked = checked;
|
||||
});
|
||||
_populateDeliveryAddress();
|
||||
// _populateDeliveryAddress();
|
||||
},
|
||||
),
|
||||
cartonTitleBox,
|
||||
Column(
|
||||
children: _getCartons(
|
||||
context,
|
||||
this._cartons,
|
||||
)),
|
||||
_isNew ? cartonTitleBox : Container(),
|
||||
_isNew
|
||||
? Column(
|
||||
children: _getCartons(
|
||||
context,
|
||||
this._cartons,
|
||||
))
|
||||
: Container(),
|
||||
_isNew ? Container() : cargoTableTitleBox,
|
||||
_isNew ? Container() : cargoTableBox,
|
||||
_isNew
|
||||
? Container()
|
||||
: LocalTitle(textKey: "box.dimension"),
|
||||
_isNew ? Container() : cartonSizeDropdown(),
|
||||
_isNew ? Container() : dimBox,
|
||||
_isNew
|
||||
? Container()
|
||||
: LocalTitle(textKey: "box.delivery_address"),
|
||||
_isNew
|
||||
? Container()
|
||||
: DefaultDeliveryAddress(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
labelKey: "box.delivery_address",
|
||||
onTap: () async {
|
||||
DeliveryAddress d =
|
||||
await Navigator.push<DeliveryAddress>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
DeliveryAddressSelection(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
deliveryAddresses:
|
||||
_deliveryAddresses)),
|
||||
);
|
||||
if (d == null) return;
|
||||
setState(() {
|
||||
_deliveryAddress = d;
|
||||
});
|
||||
}),
|
||||
]),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
createBtn,
|
||||
_isNew ? createBtn : saveBtn,
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
@@ -486,7 +615,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
CartonSize selectedCatonSize;
|
||||
Widget cartonSizeDropdown() {
|
||||
List<CartonSize> _cartonSizes =
|
||||
Provider.of<CartonSizeModel>(context).getCartonSizes;
|
||||
@@ -565,6 +693,20 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
);
|
||||
}
|
||||
|
||||
_addCargo(CargoType cargo) {
|
||||
if (cargo == null) return;
|
||||
setState(() {
|
||||
_carton.cargoTypes.remove(cargo);
|
||||
_carton.cargoTypes.add(cargo);
|
||||
});
|
||||
}
|
||||
|
||||
_removeCargo(CargoType cargo) {
|
||||
setState(() {
|
||||
_carton.cargoTypes.remove(cargo);
|
||||
});
|
||||
}
|
||||
|
||||
_save() async {
|
||||
// bool isFromShipment = _selectedCartonType == carton_from_shipments;
|
||||
// bool isSmallBag = _selectedCartonType == carton_small_bag;
|
||||
|
||||
Reference in New Issue
Block a user