2020-10-16 10:58:31 +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-16 10:58:31 +06:30
|
|
|
import 'package:fcs/domain/entities/shipment.dart';
|
|
|
|
|
import 'package:fcs/helpers/theme.dart';
|
2020-10-18 02:38:46 +06:30
|
|
|
import 'package:fcs/pages/carton/model/carton_model.dart';
|
2020-10-16 10:58:31 +06:30
|
|
|
import 'package:fcs/pages/main/model/main_model.dart';
|
2020-10-18 02:38:46 +06:30
|
|
|
import 'package:fcs/pages/main/util.dart';
|
2020-10-16 10:58:31 +06:30
|
|
|
import 'package:fcs/pages/shipment/model/shipment_model.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/defalut_delivery_address.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/display_text.dart';
|
2020-10-18 02:38:46 +06:30
|
|
|
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_button.dart';
|
2020-10-16 10:58:31 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_dropdown.dart';
|
2020-10-18 02:38:46 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_popup_menu_button.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_popupmenu.dart';
|
2020-10-16 10:58:31 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_radio_buttons.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_title.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/multi_img_controller.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_icons/flutter_icons.dart';
|
|
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
2020-10-18 02:38:46 +06:30
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2020-10-16 10:58:31 +06:30
|
|
|
|
|
|
|
|
import 'box_row.dart';
|
2020-10-18 02:38:46 +06:30
|
|
|
import 'shipment_editor.dart';
|
|
|
|
|
import 'widgets.dart';
|
2020-10-16 10:58:31 +06:30
|
|
|
|
|
|
|
|
class ShipmentInfo extends StatefulWidget {
|
|
|
|
|
final Shipment shipment;
|
|
|
|
|
ShipmentInfo({this.shipment});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_ShipmentInfoState createState() => _ShipmentInfoState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _ShipmentInfoState extends State<ShipmentInfo> {
|
|
|
|
|
var dateFormatter = new DateFormat('dd MMM yyyy');
|
|
|
|
|
final numberFormatter = new NumberFormat("#,###");
|
|
|
|
|
MultiImgController multiImgController = MultiImgController();
|
2020-10-18 02:38:46 +06:30
|
|
|
var timeFormatter = new DateFormat('jm');
|
2020-10-16 10:58:31 +06:30
|
|
|
|
|
|
|
|
TextEditingController _addressEditingController = new TextEditingController();
|
|
|
|
|
TextEditingController _fromTimeEditingController =
|
|
|
|
|
new TextEditingController();
|
|
|
|
|
TextEditingController _toTimeEditingController = new TextEditingController();
|
|
|
|
|
TextEditingController _noOfPackageEditingController =
|
|
|
|
|
new TextEditingController();
|
|
|
|
|
TextEditingController _weightEditingController = new TextEditingController();
|
|
|
|
|
TextEditingController _recipientNameEditingController =
|
|
|
|
|
new TextEditingController();
|
|
|
|
|
TextEditingController _recipientPhoneEditingController =
|
|
|
|
|
new TextEditingController();
|
|
|
|
|
TextEditingController _recipientAddressEditingController =
|
|
|
|
|
new TextEditingController();
|
|
|
|
|
TextEditingController _pickupDate = new TextEditingController();
|
|
|
|
|
TextEditingController _handlingFeeController = new TextEditingController();
|
|
|
|
|
|
|
|
|
|
Shipment _shipment;
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
var now = new DateTime.now();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_shipment = widget.shipment;
|
2020-10-18 02:38:46 +06:30
|
|
|
_loadCartons(_shipment.id);
|
2020-10-16 10:58:31 +06:30
|
|
|
|
|
|
|
|
if (widget.shipment != null) {
|
|
|
|
|
_addressEditingController.text = _shipment.address;
|
|
|
|
|
_fromTimeEditingController.text = _shipment.pickupTimeStart;
|
|
|
|
|
_toTimeEditingController.text = _shipment.pickupTimeEnd;
|
|
|
|
|
_noOfPackageEditingController.text = _shipment.numberOfPackage.toString();
|
|
|
|
|
_weightEditingController.text = _shipment.weight.toString();
|
|
|
|
|
_pickupDate.text = dateFormatter.format(_shipment.pickupDate ?? now);
|
|
|
|
|
// _handlingFeeController.text =
|
|
|
|
|
// numberFormatter.format(_shipment.handlingFee);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-18 02:38:46 +06:30
|
|
|
_loadCartons(String shipmentID) async {
|
|
|
|
|
CartonModel cartonModel = Provider.of<CartonModel>(context, listen: false);
|
|
|
|
|
var cartons = await cartonModel.getCartons(shipmentID);
|
|
|
|
|
setState(() {
|
|
|
|
|
_shipment.boxes = cartons;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-16 10:58:31 +06:30
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
MainModel mainModel = Provider.of<MainModel>(context);
|
|
|
|
|
ShipmentModel pickupModel = Provider.of<ShipmentModel>(context);
|
2020-10-18 02:38:46 +06:30
|
|
|
bool isLocalPickup = _shipment.shipmentType == shipment_local_pickup;
|
|
|
|
|
bool isCourierPickup = _shipment.shipmentType == shipment_courier_pickup;
|
|
|
|
|
bool isLocalDropoff = _shipment.shipmentType == shipment_local_dropoff;
|
|
|
|
|
bool isCourierDropoff = _shipment.shipmentType == shipment_courier_dropoff;
|
2020-10-16 10:58:31 +06:30
|
|
|
|
2020-10-18 02:38:46 +06:30
|
|
|
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment);
|
2020-10-16 10:58:31 +06:30
|
|
|
|
2020-10-18 02:38:46 +06:30
|
|
|
final fromTimeBox = DisplayText(
|
|
|
|
|
labelTextKey: 'shipment.from',
|
|
|
|
|
iconData: Icons.timer,
|
|
|
|
|
text: _shipment.pickupTimeStart,
|
|
|
|
|
);
|
|
|
|
|
final toTimeBox = DisplayText(
|
|
|
|
|
labelTextKey: 'shipment.to',
|
|
|
|
|
iconData: Icons.timer_off,
|
|
|
|
|
text: _shipment.pickupTimeEnd,
|
|
|
|
|
);
|
2020-10-16 10:58:31 +06:30
|
|
|
|
2020-10-18 02:38:46 +06:30
|
|
|
final pickupDateBox = DisplayText(
|
2020-10-16 10:58:31 +06:30
|
|
|
labelTextKey: "shipment.date",
|
|
|
|
|
iconData: Icons.date_range,
|
2020-10-18 02:38:46 +06:30
|
|
|
text: dateFormatter.format(_shipment.pickupDate),
|
2020-10-16 10:58:31 +06:30
|
|
|
);
|
2020-10-18 02:38:46 +06:30
|
|
|
var localDropoffAddressBox = Row(children: [
|
|
|
|
|
FcsIDIcon(),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: DisplayText(
|
|
|
|
|
text: mainModel.setting.usaAddress,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
]);
|
|
|
|
|
final curierDropoffAddress = Padding(
|
|
|
|
|
padding: EdgeInsets.all(8),
|
|
|
|
|
child: FloatingActionButton.extended(
|
|
|
|
|
onPressed: _openCourierWebsite,
|
|
|
|
|
icon: Icon(Icons.open_in_new, color: primaryColor),
|
|
|
|
|
label: Text(
|
|
|
|
|
'Visit courier websie \nfor nearest drop-off',
|
|
|
|
|
style: TextStyle(fontSize: 16, color: primaryColor),
|
|
|
|
|
),
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
));
|
2020-10-16 10:58:31 +06:30
|
|
|
final pickupAddressBox = DefaultDeliveryAddress(
|
|
|
|
|
deliveryAddress: _shipment.pickupAddress,
|
|
|
|
|
iconData: Icons.location_on,
|
|
|
|
|
labelKey: "shipment.location",
|
|
|
|
|
);
|
2020-10-18 02:38:46 +06:30
|
|
|
var boxModel = Provider.of<CartonModel>(context);
|
2020-10-16 10:58:31 +06:30
|
|
|
var handlingFeeBox = DisplayText(
|
|
|
|
|
labelTextKey: "shipment.handling.fee",
|
|
|
|
|
text: "10",
|
|
|
|
|
iconData: FontAwesomeIcons.moneyBill);
|
2020-10-18 02:38:46 +06:30
|
|
|
final cancelBtn = LocalButton(
|
|
|
|
|
textKey: "btn.cancel",
|
|
|
|
|
callBack: _cancel,
|
2020-10-16 10:58:31 +06:30
|
|
|
);
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
"shipment.info",
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
actions: <Widget>[
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: Icon(Icons.edit, color: primaryColor),
|
|
|
|
|
onPressed: _edit,
|
2020-10-18 02:38:46 +06:30
|
|
|
),
|
2020-10-16 10:58:31 +06:30
|
|
|
]),
|
|
|
|
|
body: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(10.0),
|
|
|
|
|
child: ListView(
|
|
|
|
|
children: <Widget>[
|
2020-10-18 02:38:46 +06:30
|
|
|
shipmentNumberBox,
|
|
|
|
|
|
2020-10-16 10:58:31 +06:30
|
|
|
LocalTitle(textKey: "shipment.type"),
|
|
|
|
|
LocalRadioButtons(
|
2020-10-18 02:38:46 +06:30
|
|
|
readOnly: true,
|
|
|
|
|
values: pickupModel.shipmentTypes,
|
|
|
|
|
selectedValue: _shipment.shipmentType,
|
|
|
|
|
),
|
2020-10-16 10:58:31 +06:30
|
|
|
// handlingFeeBox,
|
|
|
|
|
// shipmentTypeBox,
|
2020-10-18 02:38:46 +06:30
|
|
|
...(isLocalDropoff
|
|
|
|
|
? [
|
|
|
|
|
LocalTitle(textKey: "shipment.location.dropoff"),
|
|
|
|
|
localDropoffAddressBox
|
|
|
|
|
]
|
|
|
|
|
: []),
|
|
|
|
|
...(isCourierDropoff
|
|
|
|
|
? [
|
|
|
|
|
LocalTitle(textKey: "shipment.courier.dropoff"),
|
|
|
|
|
curierDropoffAddress
|
|
|
|
|
]
|
|
|
|
|
: []),
|
|
|
|
|
...(isCourierPickup || isLocalPickup
|
|
|
|
|
? [
|
|
|
|
|
LocalTitle(textKey: "shipment.location"),
|
|
|
|
|
pickupAddressBox,
|
|
|
|
|
LocalTitle(textKey: "shipment.date.time"),
|
|
|
|
|
pickupDateBox,
|
|
|
|
|
fromTimeBox,
|
|
|
|
|
toTimeBox,
|
|
|
|
|
]
|
|
|
|
|
: []),
|
2020-10-16 10:58:31 +06:30
|
|
|
// localDropoffAddress,
|
|
|
|
|
// curierDropoffAddress,
|
|
|
|
|
LocalTitle(
|
|
|
|
|
textKey: "boxes.name",
|
|
|
|
|
),
|
2020-10-18 02:38:46 +06:30
|
|
|
Column(
|
|
|
|
|
children: getBoxList(context, _shipment.boxes),
|
|
|
|
|
),
|
|
|
|
|
_shipment.currentStatus == shipment_pending_status
|
|
|
|
|
? cancelBtn
|
|
|
|
|
: Container()
|
2020-10-16 10:58:31 +06:30
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-18 02:38:46 +06:30
|
|
|
List<Widget> getBoxList(BuildContext context, List<Carton> boxes) {
|
|
|
|
|
if (boxes == null) return [];
|
2020-10-16 10:58:31 +06:30
|
|
|
return boxes.asMap().entries.map((_box) {
|
2020-10-18 02:38:46 +06:30
|
|
|
return Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(child: BoxRow(box: _box.value)),
|
|
|
|
|
],
|
2020-10-16 10:58:31 +06:30
|
|
|
);
|
|
|
|
|
}).toList();
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-18 02:38:46 +06:30
|
|
|
_edit() async {
|
|
|
|
|
bool updated = await Navigator.push<bool>(
|
|
|
|
|
context,
|
|
|
|
|
CupertinoPageRoute(
|
|
|
|
|
builder: (context) => ShipmentEditor(
|
|
|
|
|
shipment: _shipment,
|
|
|
|
|
)),
|
|
|
|
|
);
|
|
|
|
|
if (updated ?? false) {
|
|
|
|
|
ShipmentModel shipmentModel =
|
|
|
|
|
Provider.of<ShipmentModel>(context, listen: false);
|
|
|
|
|
Shipment s = await shipmentModel.getShipment(_shipment.id);
|
|
|
|
|
setState(() {
|
|
|
|
|
_shipment = s;
|
|
|
|
|
});
|
|
|
|
|
await _loadCartons(s.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cancel() {
|
|
|
|
|
showConfirmDialog(context, "shipment.cancel.confirm", () {
|
|
|
|
|
_cancelShipment();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cancelShipment() async {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
|
|
|
|
try {
|
|
|
|
|
ShipmentModel shipmentModel =
|
|
|
|
|
Provider.of<ShipmentModel>(context, listen: false);
|
|
|
|
|
await shipmentModel.cancelShipment(_shipment);
|
|
|
|
|
Navigator.pop(context, true);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_openCourierWebsite() {
|
|
|
|
|
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
|
|
|
|
|
launch("${mainModel.setting.courierWebsite}");
|
|
|
|
|
}
|
2020-10-16 10:58:31 +06:30
|
|
|
}
|