add update shipments

This commit is contained in:
Sai Naw Wun
2020-10-18 02:38:46 +06:30
parent fa9738f307
commit 4f8bde40b0
37 changed files with 596 additions and 455 deletions

View File

@@ -1,17 +1,18 @@
import 'package:fcs/domain/constants.dart';
import 'package:fcs/domain/entities/box.dart';
import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/domain/entities/shipment.dart';
import 'package:fcs/domain/vo/delivery_address.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/box/model/box_model.dart';
import 'package:fcs/pages/carton/model/carton_model.dart';
import 'package:fcs/pages/main/model/main_model.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/shipment/model/shipment_model.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/input_date.dart';
import 'package:fcs/pages/widgets/input_time.dart';
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
import 'package:fcs/pages/widgets/local_button.dart';
import 'package:fcs/pages/widgets/local_dropdown.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_radio_buttons.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/local_title.dart';
@@ -23,8 +24,11 @@ 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';
import 'package:url_launcher/url_launcher.dart';
import 'box_row.dart';
import 'shipment_editor.dart';
import 'widgets.dart';
class ShipmentInfo extends StatefulWidget {
final Shipment shipment;
@@ -38,6 +42,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
var dateFormatter = new DateFormat('dd MMM yyyy');
final numberFormatter = new NumberFormat("#,###");
MultiImgController multiImgController = MultiImgController();
var timeFormatter = new DateFormat('jm');
TextEditingController _addressEditingController = new TextEditingController();
TextEditingController _fromTimeEditingController =
@@ -59,14 +64,11 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
bool _isLoading = false;
var now = new DateTime.now();
int _currVal = 1;
String _selectedShipmentType;
@override
void initState() {
super.initState();
_selectedShipmentType = shipment_local_pickup;
_shipment = widget.shipment;
_loadCartons(_shipment.id);
if (widget.shipment != null) {
_addressEditingController.text = _shipment.address;
@@ -77,10 +79,17 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
_pickupDate.text = dateFormatter.format(_shipment.pickupDate ?? now);
// _handlingFeeController.text =
// numberFormatter.format(_shipment.handlingFee);
_currVal = _shipment.radioIndex;
}
}
_loadCartons(String shipmentID) async {
CartonModel cartonModel = Provider.of<CartonModel>(context, listen: false);
var cartons = await cartonModel.getCartons(shipmentID);
setState(() {
_shipment.boxes = cartons;
});
}
@override
void dispose() {
super.dispose();
@@ -90,70 +99,61 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
Widget build(BuildContext context) {
MainModel mainModel = Provider.of<MainModel>(context);
ShipmentModel pickupModel = Provider.of<ShipmentModel>(context);
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;
final fromTimeBox = InputTime(
labelTextKey: 'shipment.from',
iconData: Icons.timer,
controller: _fromTimeEditingController);
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment);
final toTimeBox = Container(
width: 150,
child: InputTime(
iconData: Icons.timer_off,
labelTextKey: 'shipment.to',
controller: _toTimeEditingController));
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,
);
final pickupDateBox = InputDate(
final pickupDateBox = DisplayText(
labelTextKey: "shipment.date",
iconData: Icons.date_range,
controller: _pickupDate,
);
final localDropoffAddress = DisplayText(
iconData: Icons.location_on,
labelTextKey: "Local Dropoff Address",
text: mainModel.setting.usaAddress);
final curierDropoffAddress = FloatingActionButton.extended(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: () {},
icon: Icon(Icons.arrow_right),
label: Text(
'Visit courier websie for nearest drop-off',
style: TextStyle(fontSize: 12),
),
backgroundColor: primaryColor,
text: dateFormatter.format(_shipment.pickupDate),
);
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,
));
final pickupAddressBox = DefaultDeliveryAddress(
deliveryAddress: _shipment.pickupAddress,
iconData: Icons.location_on,
labelKey: "shipment.location",
onTap: () async {
DeliveryAddress address = await Navigator.push<DeliveryAddress>(
context,
CupertinoPageRoute(
builder: (context) => DeliveryAddressSelection(
deliveryAddress: _shipment.pickupAddress,
)),
);
if (address == null) return;
setState(() {
_shipment.pickupAddress = address;
});
},
);
var boxModel = Provider.of<BoxModel>(context);
var boxModel = Provider.of<CartonModel>(context);
var handlingFeeBox = DisplayText(
labelTextKey: "shipment.handling.fee",
text: "10",
iconData: FontAwesomeIcons.moneyBill);
var shipmentTypeBox = LocalDropdown<String>(
callback: (v) {
setState(() {
_selectedShipmentType = v;
});
},
iconData: SimpleLineIcons.direction,
selectedValue: _selectedShipmentType,
values: pickupModel.shipmentTypes,
final cancelBtn = LocalButton(
textKey: "btn.cancel",
callBack: _cancel,
);
return LocalProgress(
@@ -180,44 +180,55 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
IconButton(
icon: Icon(Icons.edit, color: primaryColor),
onPressed: _edit,
)
),
]),
body: Padding(
padding: const EdgeInsets.all(10.0),
child: ListView(
children: <Widget>[
shipmentNumberBox,
LocalTitle(textKey: "shipment.type"),
LocalRadioButtons(
values: pickupModel.shipmentTypes,
selectedValue: _selectedShipmentType,
callback: (v) {
setState(() {
_selectedShipmentType = v;
});
}),
readOnly: true,
values: pickupModel.shipmentTypes,
selectedValue: _shipment.shipmentType,
),
// handlingFeeBox,
// shipmentTypeBox,
LocalTitle(textKey: "shipment.location"),
pickupAddressBox,
LocalTitle(textKey: "shipment.date.time"),
pickupDateBox,
fromTimeBox,
toTimeBox,
...(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,
]
: []),
// localDropoffAddress,
// curierDropoffAddress,
LocalTitle(
textKey: "boxes.name",
trailing: IconButton(
icon: Icon(
Icons.add_circle,
color: primaryColor,
),
onPressed: () async {},
),
),
// Column(
// children: getBoxList(context, _shipment.boxes),
// ),
Column(
children: getBoxList(context, _shipment.boxes),
),
_shipment.currentStatus == shipment_pending_status
? cancelBtn
: Container()
],
),
),
@@ -225,24 +236,62 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
);
}
List<Widget> getBoxList(BuildContext context, List<Box> boxes) {
List<Widget> getBoxList(BuildContext context, List<Carton> boxes) {
if (boxes == null) return [];
return boxes.asMap().entries.map((_box) {
return InkWell(
onTap: () async {},
child: Row(
children: [
Expanded(child: BoxRow(box: _box.value)),
InkWell(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(Icons.remove, color: primaryColor),
),
),
],
),
return Row(
children: [
Expanded(child: BoxRow(box: _box.value)),
],
);
}).toList();
}
_edit() {}
_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}");
}
}