2024-09-22 16:49:59 +06:30
|
|
|
import 'package:fcs/constants.dart';
|
2020-10-21 05:40:58 +06:30
|
|
|
import 'package:fcs/domain/entities/carton.dart';
|
2020-10-16 17:57:58 +06:30
|
|
|
import 'package:fcs/domain/entities/package.dart';
|
|
|
|
|
import 'package:fcs/domain/vo/delivery_address.dart';
|
|
|
|
|
import 'package:fcs/helpers/theme.dart';
|
2020-10-21 05:40:58 +06:30
|
|
|
import 'package:fcs/pages/carton/carton_package_table.dart';
|
|
|
|
|
import 'package:fcs/pages/carton/model/carton_model.dart';
|
2020-10-21 02:59:10 +06:30
|
|
|
import 'package:fcs/pages/carton/widgets.dart';
|
2020-10-16 17:57:58 +06:30
|
|
|
import 'package:fcs/pages/delivery/model/delivery_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/widgets/defalut_delivery_address.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/display_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
|
2024-01-25 17:40:35 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
2020-10-21 05:40:58 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_button.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_radio_buttons.dart';
|
2020-10-16 17:57:58 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_title.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
2021-09-10 14:29:55 +06:30
|
|
|
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
2020-10-16 17:57:58 +06:30
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
final DateFormat dateFormat = DateFormat("d MMM yyyy");
|
|
|
|
|
|
|
|
|
|
class DeliveryInfo extends StatefulWidget {
|
2021-09-10 12:02:08 +06:30
|
|
|
final Carton? box;
|
2020-10-16 17:57:58 +06:30
|
|
|
DeliveryInfo({this.box});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_DeliveryInfoState createState() => _DeliveryInfoState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _DeliveryInfoState extends State<DeliveryInfo> {
|
|
|
|
|
bool _isLoading = false;
|
2021-09-10 12:02:08 +06:30
|
|
|
late Carton _box;
|
2024-01-23 16:28:08 +06:30
|
|
|
|
|
|
|
|
// List<CargoType> _cargoTypes = [];
|
2020-10-16 17:57:58 +06:30
|
|
|
DeliveryAddress _deliveryAddress = new DeliveryAddress();
|
|
|
|
|
TextEditingController _widthController = new TextEditingController();
|
|
|
|
|
TextEditingController _heightController = new TextEditingController();
|
|
|
|
|
TextEditingController _lengthController = new TextEditingController();
|
|
|
|
|
double volumetricRatio = 0;
|
|
|
|
|
double shipmentWeight = 0;
|
|
|
|
|
|
2021-09-10 12:02:08 +06:30
|
|
|
late bool isMixBox;
|
|
|
|
|
late bool isFromShipments;
|
|
|
|
|
late bool isFromPackages;
|
|
|
|
|
late bool isSmallBag;
|
|
|
|
|
late bool isEdiable;
|
2020-10-21 05:40:58 +06:30
|
|
|
|
2020-10-16 17:57:58 +06:30
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
2021-09-10 15:23:13 +06:30
|
|
|
if (widget.box != null) _box = widget.box!;
|
2020-10-16 17:57:58 +06:30
|
|
|
|
|
|
|
|
//for shipment weight
|
|
|
|
|
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
|
|
|
|
|
.rate
|
|
|
|
|
.volumetricRatio;
|
|
|
|
|
_lengthController.addListener(_calShipmentWeight);
|
|
|
|
|
_widthController.addListener(_calShipmentWeight);
|
|
|
|
|
_heightController.addListener(_calShipmentWeight);
|
|
|
|
|
|
2020-10-21 05:40:58 +06:30
|
|
|
_updateBoxData();
|
|
|
|
|
_loadPackages();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_updateBoxData() {
|
2020-10-16 17:57:58 +06:30
|
|
|
_widthController.text = _box.width.toString();
|
|
|
|
|
_heightController.text = _box.height.toString();
|
|
|
|
|
_lengthController.text = _box.length.toString();
|
2024-01-23 16:28:08 +06:30
|
|
|
// _cargoTypes = _box.cargoTypes;
|
2021-09-10 15:23:13 +06:30
|
|
|
_deliveryAddress = _box.deliveryAddress!;
|
2020-10-21 05:40:58 +06:30
|
|
|
isMixBox = _box.cartonType == carton_mix_box;
|
|
|
|
|
isFromShipments = _box.cartonType == carton_from_shipments;
|
|
|
|
|
isFromPackages = _box.cartonType == carton_from_packages;
|
|
|
|
|
isSmallBag = _box.cartonType == carton_small_bag;
|
|
|
|
|
isEdiable = !isMixBox &&
|
|
|
|
|
(isFromPackages || isSmallBag) &&
|
|
|
|
|
_box.status == carton_packed_status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_loadPackages() async {
|
|
|
|
|
if (!isFromPackages && !isSmallBag) return;
|
|
|
|
|
|
|
|
|
|
if (_box.cartonType == carton_from_packages && _box.userID == null) return;
|
|
|
|
|
PackageModel packageModel =
|
|
|
|
|
Provider.of<PackageModel>(context, listen: false);
|
2021-09-10 15:23:13 +06:30
|
|
|
List<Package> packages = await packageModel.getPackages(_box.userID!, [
|
2020-10-21 05:40:58 +06:30
|
|
|
package_processed_status,
|
|
|
|
|
package_packed_status,
|
2020-10-23 01:27:23 +06:30
|
|
|
package_shipped_status,
|
|
|
|
|
package_delivered_status
|
2020-10-21 05:40:58 +06:30
|
|
|
]);
|
|
|
|
|
packages = packages.where((p) => _box.packageIDs.contains(p.id)).toList();
|
|
|
|
|
packages.forEach((p) {
|
|
|
|
|
p.isChecked = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
_box.packages = packages;
|
|
|
|
|
});
|
2020-10-16 17:57:58 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_calShipmentWeight() {
|
2024-01-24 16:54:08 +06:30
|
|
|
double l = double.tryParse(_lengthController.text) ?? 0;
|
|
|
|
|
double w = double.tryParse(_widthController.text) ?? 0;
|
|
|
|
|
double h = double.tryParse(_heightController.text) ?? 0;
|
2020-10-16 17:57:58 +06:30
|
|
|
setState(() {
|
|
|
|
|
shipmentWeight = l * w * h / volumetricRatio;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final DateFormat dateFormat = DateFormat("d MMM yyyy");
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2020-10-21 05:40:58 +06:30
|
|
|
var cartonModel = Provider.of<CartonModel>(context);
|
2020-10-16 17:57:58 +06:30
|
|
|
|
2020-10-21 05:40:58 +06:30
|
|
|
final cartonTypeBox = LocalRadioButtons(
|
|
|
|
|
readOnly: true,
|
|
|
|
|
values: cartonModel.cartonTypesInfo,
|
2021-09-10 16:48:20 +06:30
|
|
|
selectedValue: (_box.isShipmentCarton ?? false)
|
2021-09-10 15:23:13 +06:30
|
|
|
? carton_from_shipments
|
|
|
|
|
: _box.cartonType);
|
2020-10-16 17:57:58 +06:30
|
|
|
final shipmentBox = DisplayText(
|
2020-10-21 05:40:58 +06:30
|
|
|
text: _box.fcsShipmentNumber,
|
2020-10-16 17:57:58 +06:30
|
|
|
labelTextKey: "box.fcs_shipment_num",
|
|
|
|
|
iconData: Ionicons.ios_airplane,
|
|
|
|
|
);
|
|
|
|
|
final fcsIDBox = DisplayText(
|
2021-09-10 12:02:08 +06:30
|
|
|
text: _box.fcsID,
|
2020-10-16 17:57:58 +06:30
|
|
|
labelTextKey: "box.fcs.id",
|
|
|
|
|
icon: FcsIDIcon(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final customerNameBox = DisplayText(
|
2021-09-10 12:02:08 +06:30
|
|
|
text: _box.userName,
|
2020-10-16 17:57:58 +06:30
|
|
|
labelTextKey: "box.name",
|
|
|
|
|
iconData: Icons.person,
|
|
|
|
|
);
|
|
|
|
|
|
2024-01-23 16:28:08 +06:30
|
|
|
// final shipmentBoxTitle = Container(
|
|
|
|
|
// padding: EdgeInsets.only(left: 15, right: 10.0, top: 20),
|
|
|
|
|
// child: Row(
|
|
|
|
|
// children: <Widget>[
|
|
|
|
|
// Expanded(
|
|
|
|
|
// child:
|
|
|
|
|
// LocalText(context, 'box.shipment_number', color: Colors.grey),
|
|
|
|
|
// ),
|
|
|
|
|
// LocalText(context, 'box.shipment.desc', color: Colors.grey),
|
|
|
|
|
// ],
|
|
|
|
|
// ),
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
// final shipmentBoxRow = Container(
|
|
|
|
|
// padding: EdgeInsets.only(left: 15.0, right: 10.0, top: 5.0, bottom: 5.0),
|
|
|
|
|
// child: Row(
|
|
|
|
|
// children: <Widget>[
|
|
|
|
|
// Expanded(
|
|
|
|
|
// child: new Text(
|
|
|
|
|
// _selectedShipmentBox.shipmentNumber ?? "",
|
|
|
|
|
// style: textStyle,
|
|
|
|
|
// )),
|
|
|
|
|
// new Text(
|
|
|
|
|
// _selectedShipmentBox.desc ?? "",
|
|
|
|
|
// style: textStyle,
|
|
|
|
|
// ),
|
|
|
|
|
// ],
|
|
|
|
|
// ),
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
// 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),
|
|
|
|
|
// ],
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
// final shipmentWeightBox = DisplayText(
|
|
|
|
|
// text: shipmentWeight.toStringAsFixed(0),
|
|
|
|
|
// labelTextKey: "box.shipment_weight",
|
|
|
|
|
// iconData: MaterialCommunityIcons.weight,
|
|
|
|
|
// );
|
2020-10-21 05:40:58 +06:30
|
|
|
final mixCartonNumberBox = DisplayText(
|
|
|
|
|
text: _box.mixCartonNumber,
|
|
|
|
|
labelTextKey: "box.mix.carton",
|
|
|
|
|
iconData: MaterialCommunityIcons.package,
|
|
|
|
|
);
|
|
|
|
|
final deliverBtn = LocalButton(
|
|
|
|
|
textKey: "delivery.deliver.btn",
|
|
|
|
|
callBack: _deliver,
|
|
|
|
|
);
|
2020-10-16 17:57:58 +06:30
|
|
|
|
|
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: Scaffold(
|
2024-01-25 17:40:35 +06:30
|
|
|
appBar: LocalAppBar(
|
|
|
|
|
labelKey: "delivery.info.title",
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
labelColor: primaryColor,
|
|
|
|
|
arrowColor: primaryColor),
|
2020-10-21 02:59:10 +06:30
|
|
|
body: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(10.0),
|
|
|
|
|
child: ListView(children: <Widget>[
|
|
|
|
|
Center(child: getCartonNumberStatus(context, _box)),
|
|
|
|
|
LocalTitle(textKey: "box.type.title"),
|
2020-10-21 05:40:58 +06:30
|
|
|
cartonTypeBox,
|
2020-10-21 02:59:10 +06:30
|
|
|
LocalTitle(textKey: "box.shipment_info"),
|
|
|
|
|
shipmentBox,
|
2020-10-21 05:40:58 +06:30
|
|
|
isSmallBag ? mixCartonNumberBox : Container(),
|
|
|
|
|
isMixBox ? Container() : fcsIDBox,
|
|
|
|
|
isMixBox ? Container() : customerNameBox,
|
|
|
|
|
isFromPackages || isSmallBag
|
|
|
|
|
? CartonPackageTable(
|
|
|
|
|
packages: _box.packages,
|
2020-10-16 17:57:58 +06:30
|
|
|
)
|
2020-10-21 05:40:58 +06:30
|
|
|
: Container(),
|
|
|
|
|
isMixBox
|
|
|
|
|
? Container()
|
|
|
|
|
: LocalTitle(textKey: "box.delivery_address"),
|
|
|
|
|
isMixBox
|
|
|
|
|
? Container()
|
|
|
|
|
: DefaultDeliveryAddress(
|
|
|
|
|
deliveryAddress: _deliveryAddress,
|
|
|
|
|
labelKey: "box.delivery_address",
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 20,
|
2020-10-21 02:59:10 +06:30
|
|
|
),
|
2020-10-21 05:40:58 +06:30
|
|
|
!isMixBox && _box.status == carton_shipped_status
|
|
|
|
|
? deliverBtn
|
|
|
|
|
: Container(),
|
2020-10-21 02:59:10 +06:30
|
|
|
SizedBox(
|
|
|
|
|
height: 20,
|
|
|
|
|
)
|
|
|
|
|
]),
|
2020-10-16 17:57:58 +06:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 05:40:58 +06:30
|
|
|
_deliver() {
|
|
|
|
|
showConfirmDialog(context, "delivery.deliver.confirm", () {
|
|
|
|
|
_deliverCarton();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_deliverCarton() async {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
|
|
|
|
try {
|
|
|
|
|
var deliveryModel = Provider.of<DeliveryModel>(context, listen: false);
|
2021-09-10 12:02:08 +06:30
|
|
|
await deliveryModel.deliver(this._box);
|
2020-10-21 05:40:58 +06:30
|
|
|
Navigator.pop(context, true);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-16 17:57:58 +06:30
|
|
|
}
|