Files
fcs/lib/pages/carton/carton_editor.dart

991 lines
31 KiB
Dart
Raw Normal View History

2020-10-14 16:53:16 +06:30
import 'package:fcs/domain/constants.dart';
2020-10-18 02:38:46 +06:30
import 'package:fcs/domain/entities/carton.dart';
2020-10-15 03:06:13 +06:30
import 'package:fcs/domain/entities/cargo_type.dart';
2020-12-01 19:02:21 +06:30
import 'package:fcs/domain/entities/carton_size.dart';
2020-10-19 05:13:49 +06:30
import 'package:fcs/domain/entities/fcs_shipment.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/domain/entities/package.dart';
2020-10-09 17:28:42 +06:30
import 'package:fcs/domain/entities/user.dart';
2020-10-08 11:38:05 +06:30
import 'package:fcs/domain/vo/delivery_address.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/helpers/theme.dart';
2020-10-20 06:19:10 +06:30
import 'package:fcs/pages/carton/carton_package_table.dart';
2020-12-10 20:06:15 +06:30
import 'package:fcs/pages/carton_search/carton_search.dart';
2020-12-01 19:02:21 +06:30
import 'package:fcs/pages/carton_size/carton_size_list.dart';
2021-01-07 18:15:39 +06:30
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
2020-10-19 05:13:49 +06:30
import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/main/util.dart';
2020-10-09 17:28:42 +06:30
import 'package:fcs/pages/package/model/package_model.dart';
2020-10-15 03:06:13 +06:30
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
2020-10-09 17:28:42 +06:30
import 'package:fcs/pages/user_search/user_serach.dart';
2021-01-07 18:15:39 +06:30
import 'package:fcs/pages/widgets/defalut_delivery_address.dart';
import 'package:fcs/pages/widgets/delivery_address_selection.dart';
2020-10-09 17:28:42 +06:30
import 'package:fcs/pages/widgets/display_text.dart';
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
2021-01-07 18:15:39 +06:30
import 'package:fcs/pages/widgets/length_picker.dart';
2020-10-14 16:53:16 +06:30
import 'package:fcs/pages/widgets/local_button.dart';
2020-10-19 05:13:49 +06:30
import 'package:fcs/pages/widgets/local_dropdown.dart';
2020-10-14 13:17:12 +06:30
import 'package:fcs/pages/widgets/local_radio_buttons.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/widgets/local_text.dart';
2020-10-14 13:17:12 +06:30
import 'package:fcs/pages/widgets/local_title.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/widgets/progress.dart';
2020-10-14 16:53:16 +06:30
import 'package:flutter/cupertino.dart';
2020-06-04 01:36:49 +06:30
import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:provider/provider.dart';
2021-01-07 18:15:39 +06:30
import 'cargo_type_addtion.dart';
import 'carton_cargo_table.dart';
2020-12-10 20:06:15 +06:30
import 'carton_row.dart';
2020-10-18 02:38:46 +06:30
import 'model/carton_model.dart';
2020-12-01 19:02:21 +06:30
import '../carton_size/model/carton_size_model.dart';
2020-12-07 17:18:26 +06:30
import 'package_carton_editor.dart';
2020-10-20 06:19:10 +06:30
import 'widgets.dart';
2020-10-09 17:28:42 +06:30
2020-10-19 05:13:49 +06:30
class CartonEditor extends StatefulWidget {
2020-10-18 02:38:46 +06:30
final Carton box;
2020-10-19 05:13:49 +06:30
CartonEditor({this.box});
2020-06-04 01:36:49 +06:30
@override
2020-10-19 05:13:49 +06:30
_CartonEditorState createState() => _CartonEditorState();
2020-06-04 01:36:49 +06:30
}
2020-10-19 05:13:49 +06:30
class _CartonEditorState extends State<CartonEditor> {
2020-10-09 17:28:42 +06:30
TextEditingController _widthController = new TextEditingController();
TextEditingController _heightController = new TextEditingController();
TextEditingController _lengthController = new TextEditingController();
2021-01-08 17:13:51 +06:30
DeliveryAddress _deliveryAddress = new DeliveryAddress();
List<CargoType> _cargoTypes = [];
2020-06-04 01:36:49 +06:30
2020-10-20 06:19:10 +06:30
Carton _carton;
2020-06-04 01:36:49 +06:30
bool _isLoading = false;
2020-10-19 05:13:49 +06:30
bool _isNew;
User _user;
2020-10-14 13:17:12 +06:30
String _selectedCartonType;
2021-01-09 19:11:47 +06:30
2020-10-13 15:45:01 +06:30
double volumetricRatio = 0;
double shipmentWeight = 0;
2020-10-19 05:13:49 +06:30
FcsShipment _fcsShipment;
List<FcsShipment> _fcsShipments;
2020-12-07 17:18:26 +06:30
List<Carton> _cartons = [];
2021-01-07 18:15:39 +06:30
CartonSize selectedCatonSize;
2020-12-07 17:18:26 +06:30
2021-01-09 19:11:47 +06:30
//for mix carton
List<Carton> _mixCartons = [];
String _selectedMixBoxType;
//for carton from cargos
User consignee;
User sender;
2021-01-12 16:59:52 +06:30
List<Carton> _cartonsFromCartons = [];
2021-01-09 19:11:47 +06:30
2021-01-25 16:09:41 +06:30
double totalWeight;
2020-06-04 01:36:49 +06:30
@override
void initState() {
super.initState();
2020-10-14 16:53:16 +06:30
//for shipment weight
2020-10-15 03:06:13 +06:30
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
.rate
.volumetricRatio;
2020-10-13 15:45:01 +06:30
_lengthController.addListener(_calShipmentWeight);
_widthController.addListener(_calShipmentWeight);
_heightController.addListener(_calShipmentWeight);
2020-06-04 01:36:49 +06:30
if (widget.box != null) {
2020-10-20 06:19:10 +06:30
_carton = widget.box;
_deliveryAddress = _carton.deliveryAddress;
_widthController.text = _carton.width.toString();
_heightController.text = _carton.height.toString();
_lengthController.text = _carton.length.toString();
_selectedCartonType = _carton.cartonType;
2021-01-12 16:59:52 +06:30
_cargoTypes = _carton.cargoTypes.map((e) => e.clone()).toList();
2020-10-19 05:13:49 +06:30
_isNew = false;
2021-01-10 15:56:27 +06:30
_user = User(
id: _carton.userID, fcsID: _carton.fcsID, name: _carton.userName);
consignee = User(
2021-01-12 16:59:52 +06:30
id: _carton.userID, fcsID: _carton.fcsID, name: _carton.userName);
2021-01-10 15:56:27 +06:30
sender = User(
id: _carton.senderID,
2021-01-12 16:59:52 +06:30
fcsID: _carton.senderFCSID,
2021-01-10 15:56:27 +06:30
name: _carton.senderName);
2021-01-09 19:11:47 +06:30
_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) {
_getCartonSize();
}
2020-06-04 01:36:49 +06:30
} else {
2020-10-24 06:14:07 +06:30
_carton = Carton(
cargoTypes: [],
packages: [],
);
2020-12-11 17:34:56 +06:30
_lengthController.text = "0";
_widthController.text = "0";
_heightController.text = "0";
2020-10-19 05:13:49 +06:30
_isNew = true;
2020-10-14 16:53:16 +06:30
_selectedCartonType = carton_from_packages;
2021-01-08 17:13:51 +06:30
_selectedMixBoxType = mix_delivery;
2020-10-19 05:13:49 +06:30
_loadFcsShipments();
2020-06-04 01:36:49 +06:30
}
}
2020-10-19 05:13:49 +06:30
_loadFcsShipments() async {
FcsShipmentModel fcsShipmentModel =
Provider.of<FcsShipmentModel>(context, listen: false);
var fcsShipments = await fcsShipmentModel.getActiveFcsShipments();
2020-10-20 06:19:10 +06:30
var fcsShipment = fcsShipments
.firstWhere((e) => e.id == _carton.fcsShipmentID, orElse: () => null);
2020-10-19 05:13:49 +06:30
setState(() {
_fcsShipments = fcsShipments;
_fcsShipment = fcsShipment;
});
}
_loadPackages() async {
if (_user == null) return;
PackageModel packageModel =
Provider.of<PackageModel>(context, listen: false);
2020-10-21 02:59:10 +06:30
List<Package> packages = await packageModel.getPackages(
_user.id, [package_processed_status, package_packed_status]);
if (_isNew) {
String prevCompare;
packages.forEach((p) {
String compare = (p.deliveryAddress?.fullName ?? "") +
(p.deliveryAddress?.phoneNumber ?? "");
if (prevCompare != null && compare == prevCompare) {
p.isChecked = true;
} else {
p.isChecked = false;
}
if (prevCompare == null) {
p.isChecked = true;
prevCompare = compare;
}
});
} else {
packages.forEach((p) {
if (_carton.packages.contains(p)) {
p.isChecked = _carton.packages.firstWhere((cp) => cp == p).isChecked;
} else {
p.isChecked = false;
}
});
}
2020-10-19 05:13:49 +06:30
setState(() {
2020-10-20 06:19:10 +06:30
_carton.packages = packages;
2020-10-19 05:13:49 +06:30
});
2021-01-07 18:15:39 +06:30
// _populateDeliveryAddress();
2020-10-19 05:13:49 +06:30
}
2021-01-07 18:15:39 +06:30
// _populateDeliveryAddress() {
// if (_carton.packages == null) return;
// var d = _carton.packages
// .firstWhere((p) => p.isChecked && p.deliveryAddress != null,
// orElse: () => null)
// ?.deliveryAddress;
// setState(() {
// _deliveryAddress = d;
// });
// }
2020-10-19 05:13:49 +06:30
2020-10-13 15:45:01 +06:30
_calShipmentWeight() {
double l = double.parse(_lengthController.text, (s) => 0);
double w = double.parse(_widthController.text, (s) => 0);
double h = double.parse(_heightController.text, (s) => 0);
setState(() {
shipmentWeight = l * w * h / volumetricRatio;
});
}
2021-01-08 17:13:51 +06:30
_getCartonSize() {
2021-01-07 18:15:39 +06:30
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) {
2021-01-08 17:13:51 +06:30
selectedCatonSize = CartonSize(
id: c.id,
name: c.name,
length: c.length,
width: c.width,
height: c.height);
2021-01-07 18:15:39 +06:30
}
});
}
2020-06-04 01:36:49 +06:30
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
2020-10-18 02:38:46 +06:30
var boxModel = Provider.of<CartonModel>(context);
2021-01-09 19:11:47 +06:30
bool isFromPackages = _selectedCartonType == carton_from_packages;
2021-01-11 19:35:26 +06:30
bool isFromCartons = _selectedCartonType == carton_from_cartons;
2020-10-20 06:19:10 +06:30
bool isMixBox = _selectedCartonType == carton_mix_box;
2020-12-10 20:06:15 +06:30
2020-10-20 06:19:10 +06:30
final shipmentBox = DisplayText(
text: _carton.fcsShipmentNumber,
labelTextKey: "box.fcs_shipment_num",
iconData: Ionicons.ios_airplane,
);
2020-12-10 20:06:15 +06:30
2020-12-02 20:55:00 +06:30
var fcsShipmentsBox = Container(
padding: EdgeInsets.only(top: 10),
child: LocalDropdown<FcsShipment>(
callback: (v) {
setState(() {
_fcsShipment = v;
});
},
labelKey: "shipment.pack.fcs.shipment",
iconData: Ionicons.ios_airplane,
display: (u) => u.shipmentNumber,
selectedValue: _fcsShipment,
values: _fcsShipments,
));
final fcsIDBox = Container(
2021-01-12 16:59:52 +06:30
padding: EdgeInsets.only(top: 15),
2020-12-02 20:55:00 +06:30
child: Row(
children: <Widget>[
Expanded(
child: DisplayText(
text: _user?.fcsID ?? "",
labelTextKey: "box.fcs.id",
icon: FcsIDIcon(),
)),
_isNew
? IconButton(
icon: Icon(Icons.search, color: primaryColor),
2021-01-10 15:56:27 +06:30
onPressed: () => searchUser(context, onUserSelect: (u) {
2020-12-02 20:55:00 +06:30
setState(() {
this._user = u;
_loadPackages();
});
2021-01-10 15:56:27 +06:30
}, popPage: true))
2020-12-02 20:55:00 +06:30
: Container(),
],
));
2020-10-09 17:28:42 +06:30
2020-10-14 13:17:12 +06:30
final namebox = DisplayText(
2020-10-19 05:13:49 +06:30
text: _user?.name ?? "",
2020-10-14 13:17:12 +06:30
labelTextKey: "box.name",
iconData: Icons.person,
);
2020-10-09 17:28:42 +06:30
2020-10-14 16:53:16 +06:30
final createBtn = LocalButton(
2020-12-07 17:18:26 +06:30
textKey: "box.complete.packaging",
2021-01-08 17:13:51 +06:30
callBack: () {
Navigator.pop(context);
},
2020-10-14 16:53:16 +06:30
);
2020-10-20 06:19:10 +06:30
final saveBtn = LocalButton(
textKey: "box.cargo.save.btn",
callBack: _save,
2020-10-14 16:53:16 +06:30
);
2020-10-19 05:13:49 +06:30
final cartonTypeBox = LocalRadioButtons(
2020-10-20 06:19:10 +06:30
readOnly: !_isNew,
2020-10-19 05:13:49 +06:30
values: boxModel.cartonTypes,
selectedValue: _selectedCartonType,
callback: (v) {
setState(() {
_selectedCartonType = v;
});
});
2020-10-09 17:28:42 +06:30
2020-12-10 20:06:15 +06:30
final cartonTitleBox = Container(
child: LocalTitle(
textKey: "boxes.title",
trailing: IconButton(
icon: Icon(
Icons.add_circle,
color: primaryColor,
),
2021-01-08 17:13:51 +06:30
onPressed: _addCarton),
2020-12-10 20:06:15 +06:30
),
);
final mixTypeBox = Container(
2020-12-11 17:34:56 +06:30
padding: EdgeInsets.only(top: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.only(left: 5),
child: LocalText(
context,
"box.mix_type",
color: primaryColor,
fontSize: 15,
fontWeight: FontWeight.bold,
)),
Row(
2021-01-08 17:13:51 +06:30
children: boxModel.mixBoxTypes.map((e) {
2020-12-11 17:34:56 +06:30
return Row(
children: [
Radio(
value: e,
2021-01-08 17:13:51 +06:30
groupValue: _selectedMixBoxType,
2020-12-11 17:34:56 +06:30
activeColor: primaryColor,
onChanged: (v) {
setState(() {
2021-01-08 17:13:51 +06:30
_selectedMixBoxType = v;
2020-12-11 17:34:56 +06:30
});
},
),
Text(e),
],
);
}).toList(),
),
],
),
);
2020-12-10 20:06:15 +06:30
2021-01-10 15:56:27 +06:30
final mixTypeDisplayBox = Container(
padding: EdgeInsets.only(top: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.only(left: 5),
child: LocalText(
context,
"box.mix_type",
color: primaryColor,
fontSize: 15,
fontWeight: FontWeight.bold,
)),
Row(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(
Icons.check,
color: primaryColor,
),
),
Text(_selectedMixBoxType ?? "")
],
)
],
),
);
2020-12-10 20:06:15 +06:30
final mixcartonTitleBox = Container(
child: LocalTitle(
textKey: "box.mix_caton_title",
trailing: IconButton(
icon: Icon(
Icons.add_circle,
color: primaryColor,
),
2021-01-09 19:11:47 +06:30
onPressed: () async {
2021-01-12 16:59:52 +06:30
boxModel.selectedIndexFilter = 1;
2021-01-09 19:11:47 +06:30
searchCarton(context, callbackCartonSelect: (c) {
_addMixCarton(c);
});
},
2020-12-10 20:06:15 +06:30
),
),
);
2021-01-07 18:15:39 +06:30
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(() {
2021-01-25 16:09:41 +06:30
_cargoTypes.addAll(
cargos.where((e) => !_cargoTypes.contains(e)).toList());
2021-01-07 18:15:39 +06:30
});
}),
);
final cargoTableBox = CargoTable(
isNew: _isNew,
2021-01-08 17:13:51 +06:30
cargoTypes: _cargoTypes,
2021-01-07 18:15:39 +06:30
onRemove: (c) => _removeCargo(c),
2021-01-25 16:09:41 +06:30
onUpdate: (c) => _updateCargo(c),
2021-01-07 18:15:39 +06:30
);
2020-12-10 20:06:15 +06:30
2021-01-07 18:15:39 +06:30
final lengthBox = LengthPicker(
controller: _lengthController,
lableKey: "box.length",
2021-01-23 23:55:53 +06:30
isReadOnly: false,
2021-01-07 18:15:39 +06:30
);
final widthBox = LengthPicker(
controller: _widthController,
lableKey: "box.width",
2021-01-23 23:55:53 +06:30
isReadOnly: false,
2021-01-07 18:15:39 +06:30
);
final heightBox = LengthPicker(
controller: _heightController,
lableKey: "box.height",
2021-01-23 23:55:53 +06:30
isReadOnly: false,
2021-01-07 18:15:39 +06:30
);
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),
],
);
2021-01-09 19:11:47 +06:30
final createMixCarton = LocalButton(
2021-01-12 16:59:52 +06:30
textKey: _isNew ? "box.mix_carton_btn" : "box.mix_carton.update.btn",
2021-01-09 19:11:47 +06:30
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),
2021-01-10 15:56:27 +06:30
onPressed: () => searchUser(context, onUserSelect: (u) {
2021-01-09 19:11:47 +06:30
setState(() {
this.consignee = u;
});
2021-01-10 15:56:27 +06:30
}, popPage: true)),
2021-01-09 19:11:47 +06:30
],
);
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),
2021-01-10 15:56:27 +06:30
onPressed: () => searchUser(context, onUserSelect: (u) {
2021-01-09 19:11:47 +06:30
setState(() {
this.sender = u;
});
2021-01-10 15:56:27 +06:30
}, popPage: true)),
2021-01-09 19:11:47 +06:30
],
);
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,
],
),
);
2020-06-04 01:36:49 +06:30
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
leading: new IconButton(
2021-01-12 16:59:52 +06:30
icon:
new Icon(CupertinoIcons.back, color: primaryColor, size: 30),
onPressed: () => Navigator.of(context).pop()),
2020-10-09 17:28:42 +06:30
shadowColor: Colors.transparent,
backgroundColor: Colors.white,
2020-12-07 17:18:26 +06:30
title: LocalText(
context,
2021-01-08 17:13:51 +06:30
_isNew ? "box.info.title" : "box.edit.title",
2020-12-07 17:18:26 +06:30
fontSize: 20,
color: primaryColor,
),
2020-06-04 01:36:49 +06:30
),
2020-10-14 13:17:12 +06:30
body: Padding(
2020-10-19 05:13:49 +06:30
padding: const EdgeInsets.all(8.0),
2020-10-14 13:17:12 +06:30
child: ListView(
shrinkWrap: true,
children: [
2020-10-20 06:19:10 +06:30
_isNew
? Container()
: Center(child: getCartonNumberStatus(context, _carton)),
2020-10-14 13:17:12 +06:30
LocalTitle(textKey: "box.type.title"),
2020-10-19 05:13:49 +06:30
cartonTypeBox,
2020-10-14 13:17:12 +06:30
LocalTitle(textKey: "box.shipment_info"),
2020-10-20 06:19:10 +06:30
_isNew ? fcsShipmentsBox : shipmentBox,
2021-01-10 15:56:27 +06:30
isMixBox
? _isNew
? mixTypeBox
: mixTypeDisplayBox
: Container(),
2020-10-20 06:19:10 +06:30
...(isMixBox
? [
2020-12-10 20:06:15 +06:30
mixcartonTitleBox,
Column(
2021-01-08 17:13:51 +06:30
children: _getMixCartons(context, this._mixCartons)),
2020-10-20 06:19:10 +06:30
]
: [
2021-01-09 19:11:47 +06:30
isFromPackages ? fcsIDBox : Container(),
isFromPackages ? namebox : Container(),
isFromPackages
? CartonPackageTable(
packages: _carton.packages,
onSelect: (p, checked) {
2021-01-25 23:45:09 +06:30
// if (checked &&
// _deliveryAddress != null &&
// p.deliveryAddress?.id !=
// _deliveryAddress.id) {
// return;
// }
2021-01-09 19:11:47 +06:30
setState(() {
p.isChecked = checked;
});
// _populateDeliveryAddress();
},
)
: Container(),
2021-01-11 19:35:26 +06:30
isFromCartons
2021-01-09 19:11:47 +06:30
? Container(
padding: const EdgeInsets.only(top: 15),
child: Row(
children: [
Flexible(child: consigneeBox),
Flexible(child: shipperBox)
],
),
)
: Container(),
2021-01-07 18:15:39 +06:30
_isNew ? cartonTitleBox : Container(),
_isNew
? Column(
children: _getCartons(
2021-01-09 19:11:47 +06:30
context,
isFromPackages
? this._cartons
2021-01-12 16:59:52 +06:30
: this._cartonsFromCartons))
2021-01-07 18:15:39 +06:30
: 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,
2021-01-12 16:59:52 +06:30
user: User(
id: _carton.userID,
name: _carton.userName))),
2021-01-07 18:15:39 +06:30
);
if (d == null) return;
setState(() {
_deliveryAddress = d;
});
}),
2020-10-20 06:19:10 +06:30
]),
2020-12-07 17:18:26 +06:30
SizedBox(
height: 20,
),
2021-01-11 19:35:26 +06:30
isFromPackages || isFromCartons
2021-01-09 19:11:47 +06:30
? _isNew
? createBtn
: saveBtn
: Container(),
isMixBox ? createMixCarton : Container(),
2020-10-14 13:17:12 +06:30
SizedBox(
height: 20,
),
],
),
2020-06-04 01:36:49 +06:30
),
),
);
}
2020-12-07 17:18:26 +06:30
List<Widget> _getCartons(BuildContext context, List<Carton> cartons) {
2021-01-08 17:13:51 +06:30
return cartons.asMap().entries.map((c) {
2020-12-10 20:06:15 +06:30
return InkWell(
2021-01-08 17:13:51 +06:30
onTap: () async {
2021-01-09 19:11:47 +06:30
bool isFromPackages = _selectedCartonType == carton_from_packages;
2021-01-11 19:35:26 +06:30
bool isFromCartons = _selectedCartonType == carton_from_cartons;
2021-01-09 19:11:47 +06:30
if (isFromPackages) {
_loadPackages();
c.value.packages = _carton.packages;
Carton _c = await Navigator.push(
context,
CupertinoPageRoute(
2021-01-10 15:56:27 +06:30
builder: (context) => PackageCartonEditor(
carton: c.value,
isNew: false,
consignee: _user,
)),
2021-01-09 19:11:47 +06:30
);
if (_c == null) return;
cartons.removeWhere((item) => item.id == _c.id);
cartons.insert(c.key, _c);
setState(() {});
}
2021-01-08 17:13:51 +06:30
},
2020-12-10 20:06:15 +06:30
child: CartonRow(
2021-01-08 17:13:51 +06:30
key: ValueKey(c.value.id),
box: c.value,
2020-12-07 17:18:26 +06:30
),
2020-12-10 20:06:15 +06:30
);
}).toList();
}
List<Widget> _getMixCartons(BuildContext context, List<Carton> cartons) {
return cartons.map((c) {
2021-01-09 19:11:47 +06:30
return CartonRow(
key: ValueKey(c.id),
box: c,
onRemove: (carton) {
_removeMixCarton(carton);
},
2020-12-07 17:18:26 +06:30
);
}).toList();
}
2020-12-01 19:02:21 +06:30
Widget cartonSizeDropdown() {
List<CartonSize> _cartonSizes =
2020-12-02 20:55:00 +06:30
Provider.of<CartonSizeModel>(context).getCartonSizes;
2020-12-01 19:02:21 +06:30
return Padding(
2020-12-02 20:55:00 +06:30
padding: const EdgeInsets.only(top: 10),
2020-12-01 19:02:21 +06:30
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(left: 0, right: 10),
child: Icon(AntDesign.CodeSandbox, color: primaryColor),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(right: 18.0),
child: LocalText(
context,
"box.carton_size",
color: Colors.black54,
fontSize: 16,
),
),
2020-12-02 20:55:00 +06:30
DropdownButton<CartonSize>(
2020-12-01 19:02:21 +06:30
isDense: true,
value: selectedCatonSize,
style: TextStyle(color: Colors.black, fontSize: 14),
underline: Container(
height: 1,
color: Colors.grey,
),
2020-12-02 20:55:00 +06:30
onChanged: (CartonSize newValue) {
2020-12-01 19:02:21 +06:30
setState(() {
2020-12-02 20:55:00 +06:30
if (newValue.name == MANAGE_CARTONSIZE) {
2020-12-01 19:02:21 +06:30
selectedCatonSize = null;
_manageCartonSize();
return;
}
selectedCatonSize = newValue;
2020-12-02 20:55:00 +06:30
_widthController.text =
selectedCatonSize.width.toString();
_heightController.text =
selectedCatonSize.height.toString();
_lengthController.text =
selectedCatonSize.length.toString();
2020-12-01 19:02:21 +06:30
});
},
isExpanded: true,
2020-12-02 20:55:00 +06:30
items: _cartonSizes
.map<DropdownMenuItem<CartonSize>>((CartonSize value) {
return DropdownMenuItem<CartonSize>(
2020-12-01 19:02:21 +06:30
value: value,
2020-12-02 20:55:00 +06:30
child: Text(value.name ?? "",
2020-12-01 19:02:21 +06:30
overflow: TextOverflow.ellipsis,
style: TextStyle(
2020-12-02 20:55:00 +06:30
color: value.name == MANAGE_CARTONSIZE
2020-12-01 19:02:21 +06:30
? secondaryColor
: primaryColor)),
);
}).toList(),
),
],
),
),
],
),
);
}
_manageCartonSize() {
Navigator.push<Package>(
context,
CupertinoPageRoute(builder: (context) => CartonSizeList()),
);
}
2021-01-25 16:09:41 +06:30
_removeCargo(CargoType cargo) {
2021-01-07 18:15:39 +06:30
setState(() {
2021-01-08 17:13:51 +06:30
_cargoTypes.remove(cargo);
2021-01-07 18:15:39 +06:30
});
}
2021-01-25 16:09:41 +06:30
_updateCargo(CargoType cargo) {
2021-01-07 18:15:39 +06:30
setState(() {
2021-01-25 16:09:41 +06:30
var _c =
_cargoTypes.firstWhere((e) => e.id == cargo.id, orElse: () => null);
if (_c != null) {
_c.weight = cargo.weight;
_c.qty = cargo.qty;
}
2021-01-07 18:15:39 +06:30
});
}
2021-01-08 17:13:51 +06:30
_addCarton() async {
bool isFromPackages = _selectedCartonType == carton_from_packages;
2021-01-11 19:35:26 +06:30
bool isFromCartons = _selectedCartonType == carton_from_cartons;
2021-01-09 19:11:47 +06:30
if (_fcsShipment == null && _isNew) {
showMsgDialog(context, "Error", "Please select FCS shipment");
return;
}
2021-01-08 17:13:51 +06:30
if (_user == null && isFromPackages) {
showMsgDialog(context, "Error", "Please select FCS ID");
return;
}
2021-01-09 19:11:47 +06:30
2021-01-11 19:35:26 +06:30
if (consignee == null && isFromCartons) {
2021-01-09 19:11:47 +06:30
showMsgDialog(context, "Error", "Please select consignee's FCS ID");
return;
}
2021-01-11 19:35:26 +06:30
if (sender == null && isFromCartons) {
2021-01-09 19:11:47 +06:30
showMsgDialog(context, "Error", "Please select sender's FCS ID");
2021-01-08 17:13:51 +06:30
return;
}
double l = double.parse(_lengthController.text, (s) => 0);
double w = double.parse(_widthController.text, (s) => 0);
double h = double.parse(_heightController.text, (s) => 0);
Carton carton = Carton();
carton.id = _carton.id;
carton.cartonType = _selectedCartonType;
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
2021-01-09 19:11:47 +06:30
if (isFromPackages) {
carton.userID = _user?.id;
carton.fcsID = _user?.fcsID;
carton.userName = _user?.name;
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
}
2021-01-11 19:35:26 +06:30
if (isFromCartons) {
2021-01-12 16:59:52 +06:30
carton.userID = consignee?.id;
carton.fcsID = consignee?.fcsID;
carton.userName = consignee?.name;
2021-01-09 19:11:47 +06:30
carton.senderID = sender?.id;
carton.senderFCSID = sender?.fcsID;
carton.senderName = sender?.name;
}
2021-01-08 17:13:51 +06:30
carton.cargoTypes = _carton.cargoTypes;
carton.length = l;
carton.width = w;
carton.height = h;
carton.deliveryAddress = _carton.deliveryAddress;
try {
Carton _c = await Navigator.push(
context,
CupertinoPageRoute(
2021-01-10 15:56:27 +06:30
builder: (context) => PackageCartonEditor(
carton: carton,
isNew: _isNew,
consignee: _user,
)),
2021-01-08 17:13:51 +06:30
);
if (_c == null) return;
var cartonModel = Provider.of<CartonModel>(context, listen: false);
Carton _carton = await cartonModel.getCarton(_c.id);
2021-01-09 19:11:47 +06:30
if (isFromPackages) {
_cartons.add(_carton);
}
2021-01-11 19:35:26 +06:30
if (isFromCartons) {
2021-01-12 16:59:52 +06:30
_cartonsFromCartons.add(_carton);
2021-01-09 19:11:47 +06:30
}
2021-01-08 17:13:51 +06:30
setState(() {});
} catch (e) {
showMsgDialog(context, "Error", e.toString());
}
}
2021-01-09 19:11:47 +06:30
_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 {
2021-01-08 17:13:51 +06:30
if (_fcsShipment == null && _isNew) {
showMsgDialog(context, "Error", "Please select FCS shipment");
return;
}
2021-01-09 19:11:47 +06:30
if ((this._mixCartons?.length ?? 0) == 0) {
showMsgDialog(context, "Error", "Expect at least one carton");
return;
}
2021-01-08 17:13:51 +06:30
Carton carton = Carton();
carton.id = _carton.id;
carton.cartonType = _selectedCartonType;
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
carton.mixBoxType = _selectedMixBoxType;
2021-01-09 19:11:47 +06:30
carton.mixCartons = this._mixCartons;
setState(() {
_isLoading = true;
});
try {
CartonModel cartonModel =
Provider.of<CartonModel>(context, listen: false);
if (_isNew) {
2021-01-10 15:56:27 +06:30
await cartonModel.createCarton(carton);
2021-01-09 19:11:47 +06:30
} else {
2021-01-10 15:56:27 +06:30
await cartonModel.updateCarton(carton);
2021-01-09 19:11:47 +06:30
}
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
2021-01-08 17:13:51 +06:30
}
2020-10-19 05:13:49 +06:30
_save() async {
2021-01-08 17:13:51 +06:30
bool isFromPackages = _selectedCartonType == carton_from_packages;
2021-01-12 16:59:52 +06:30
bool isFromCartons = _selectedCartonType == carton_from_cartons;
if ((_cargoTypes?.length ?? 0) == 0 && (isFromPackages || isFromCartons)) {
2021-01-08 17:13:51 +06:30
showMsgDialog(context, "Error", "Expect at least one cargo type");
return;
}
2021-01-25 16:09:41 +06:30
if (_cargoTypes.where((c) => c.weight <= 0).isNotEmpty) {
showMsgDialog(context, "Error", "Invalid cargo weight");
return;
}
2021-01-08 17:13:51 +06:30
double l = double.parse(_lengthController.text, (s) => 0);
double w = double.parse(_widthController.text, (s) => 0);
double h = double.parse(_heightController.text, (s) => 0);
2021-01-12 16:59:52 +06:30
if ((l <= 0 || w <= 0 || h <= 0) && (isFromPackages || isFromCartons)) {
2021-01-08 17:13:51 +06:30
showMsgDialog(context, "Error", "Invalid dimension");
return;
}
2021-01-12 16:59:52 +06:30
if (_deliveryAddress == null && (isFromPackages || isFromCartons)) {
2021-01-08 17:13:51 +06:30
showMsgDialog(context, "Error", "Invalid delivery address");
return;
}
Carton carton = Carton();
carton.id = _carton.id;
carton.cartonType = _selectedCartonType;
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
2021-01-09 19:11:47 +06:30
if (isFromPackages) {
carton.userID = _user?.id;
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
}
2021-01-12 16:59:52 +06:30
if (isFromCartons) {
carton.userID = consignee?.id;
2021-01-09 19:11:47 +06:30
carton.senderID = sender?.id;
}
2021-01-08 17:13:51 +06:30
carton.cargoTypes = _cargoTypes;
carton.length = l;
carton.width = w;
carton.height = h;
carton.deliveryAddress = _deliveryAddress;
setState(() {
_isLoading = true;
});
try {
CartonModel cartonModel =
Provider.of<CartonModel>(context, listen: false);
await cartonModel.updateCarton(carton);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
2020-10-19 05:13:49 +06:30
}
2020-06-04 01:36:49 +06:30
}