add update shipments
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import 'package:fcs/domain/entities/box.dart';
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class BoxRow extends StatelessWidget {
|
||||
final Box box;
|
||||
final Carton box;
|
||||
|
||||
const BoxRow({Key key, this.box}) : super(key: key);
|
||||
|
||||
@@ -27,9 +27,7 @@ class BoxRow extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
box.deliveryAddress.fullName == null
|
||||
? ''
|
||||
: box.deliveryAddress.fullName,
|
||||
box.deliveryAddress?.fullName ?? "",
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0,
|
||||
color: Colors.black,
|
||||
@@ -39,9 +37,7 @@ class BoxRow extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
box.deliveryAddress.addressLine1 == null
|
||||
? ''
|
||||
: box.deliveryAddress.addressLine1,
|
||||
box.deliveryAddress?.addressLine1 ?? "",
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
@@ -49,9 +45,7 @@ class BoxRow extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
box.deliveryAddress.addressLine2 == null
|
||||
? ''
|
||||
: box.deliveryAddress.addressLine2,
|
||||
box.deliveryAddress?.addressLine2 ?? "",
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
@@ -59,9 +53,7 @@ class BoxRow extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
box.deliveryAddress.city == null
|
||||
? ''
|
||||
: box.deliveryAddress.city,
|
||||
box.deliveryAddress?.city ?? "",
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
@@ -69,9 +61,7 @@ class BoxRow extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
box.deliveryAddress.state == null
|
||||
? ''
|
||||
: box.deliveryAddress.state,
|
||||
box.deliveryAddress?.state ?? "",
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
@@ -79,9 +69,7 @@ class BoxRow extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
box.deliveryAddress.phoneNumber == null
|
||||
? ''
|
||||
: "Phone:${box.deliveryAddress.phoneNumber}",
|
||||
box.deliveryAddress?.phoneNumber ?? "",
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
|
||||
@@ -117,6 +117,7 @@ class ShipmentModel extends BaseModel {
|
||||
var q = Firestore.instance
|
||||
.collection("$path")
|
||||
.where("is_delivered", isEqualTo: false)
|
||||
.where("is_canceled", isEqualTo: false)
|
||||
.where("is_deleted", isEqualTo: false);
|
||||
|
||||
if (forCustomer) {
|
||||
@@ -144,6 +145,21 @@ class ShipmentModel extends BaseModel {
|
||||
shipment_courier_dropoff
|
||||
];
|
||||
|
||||
Future<Shipment> getShipment(String shipmentID) async {
|
||||
String path = "/$shipments_collection";
|
||||
try {
|
||||
var ref = Firestore.instance.collection("$path").document(shipmentID);
|
||||
var snap = await ref.get(source: Source.server);
|
||||
if (snap.exists) {
|
||||
var s = Shipment.fromMap(snap.data, snap.documentID);
|
||||
return s;
|
||||
}
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void initUser(user) {
|
||||
super.initUser(user);
|
||||
}
|
||||
@@ -155,4 +171,8 @@ class ShipmentModel extends BaseModel {
|
||||
Future<void> updateShipment(Shipment shipment) {
|
||||
return Services.instance.shipmentService.updateShipment(shipment);
|
||||
}
|
||||
|
||||
Future<void> cancelShipment(Shipment shipment) {
|
||||
return Services.instance.shipmentService.cancelShipment(shipment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:fcs/domain/entities/box.dart';
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/box/cargo_type_editor.dart';
|
||||
import 'package:fcs/pages/carton/cargo_type_editor.dart';
|
||||
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
|
||||
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
|
||||
import 'package:fcs/pages/widgets/defalut_delivery_address.dart';
|
||||
@@ -20,7 +20,7 @@ import 'package:flutter_icons/flutter_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class ShipmentBoxEditor extends StatefulWidget {
|
||||
final Box box;
|
||||
final Carton box;
|
||||
ShipmentBoxEditor({this.box});
|
||||
|
||||
@override
|
||||
@@ -32,7 +32,7 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
TextEditingController _widthCtl = new TextEditingController();
|
||||
TextEditingController _heightCtl = new TextEditingController();
|
||||
|
||||
Box _box;
|
||||
Carton _box;
|
||||
bool _isLoading = false;
|
||||
bool _isNew;
|
||||
double volumetricRatio = 0;
|
||||
@@ -57,7 +57,7 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
|
||||
_isNew = true;
|
||||
_box = Box(cargoTypes: []);
|
||||
_box = Carton(cargoTypes: []);
|
||||
_box.deliveryAddress = shipmentModel.defalutAddress;
|
||||
|
||||
_lengthCtl.text = "12";
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
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/delivery_address/model/delivery_address_model.dart';
|
||||
import 'package:fcs/pages/main/model/main_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
@@ -11,24 +10,23 @@ 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/fcs_id_icon.dart';
|
||||
import 'package:fcs/pages/widgets/input_date.dart';
|
||||
import 'package:fcs/pages/widgets/input_time.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';
|
||||
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';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'box_row.dart';
|
||||
import 'shipment_box_editor.dart';
|
||||
import 'widgets.dart';
|
||||
|
||||
class ShipmentEditor extends StatefulWidget {
|
||||
final Shipment shipment;
|
||||
@@ -40,55 +38,37 @@ class ShipmentEditor extends StatefulWidget {
|
||||
|
||||
class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
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 =
|
||||
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();
|
||||
bool _isNew;
|
||||
|
||||
int _currVal = 1;
|
||||
String _selectedShipmentType;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selectedShipmentType = shipment_local_pickup;
|
||||
|
||||
if (widget.shipment != null) {
|
||||
_isNew = false;
|
||||
_shipment = widget.shipment;
|
||||
_addressEditingController.text = _shipment.address;
|
||||
_selectedShipmentType = _shipment.shipmentType;
|
||||
_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);
|
||||
_currVal = _shipment.radioIndex;
|
||||
} else {
|
||||
_isNew = true;
|
||||
_selectedShipmentType = shipment_local_pickup;
|
||||
_pickupDate.text = dateFormatter.format(now);
|
||||
_fromTimeEditingController.text = "${(now.hour)}:${(now.minute)}";
|
||||
_toTimeEditingController.text = "${(now.hour)}:${(now.minute)}";
|
||||
_fromTimeEditingController.text = "${timeFormatter.format(now)}";
|
||||
_toTimeEditingController.text = "${timeFormatter.format(now)}";
|
||||
_shipment = Shipment(boxes: []);
|
||||
var shipmentModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
@@ -106,7 +86,11 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
Widget build(BuildContext context) {
|
||||
MainModel mainModel = Provider.of<MainModel>(context);
|
||||
ShipmentModel pickupModel = Provider.of<ShipmentModel>(context);
|
||||
|
||||
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment);
|
||||
bool isLocalPickup = _selectedShipmentType == shipment_local_pickup;
|
||||
bool isCourierPickup = _selectedShipmentType == shipment_courier_pickup;
|
||||
bool isLocalDropoff = _selectedShipmentType == shipment_local_dropoff;
|
||||
bool isCourierDropoff = _selectedShipmentType == shipment_courier_dropoff;
|
||||
final fromTimeBox = InputTime(
|
||||
labelTextKey: 'shipment.from',
|
||||
iconData: Icons.timer,
|
||||
@@ -124,20 +108,17 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
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,
|
||||
);
|
||||
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,
|
||||
@@ -156,28 +137,22 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
});
|
||||
},
|
||||
);
|
||||
var boxModel = Provider.of<BoxModel>(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,
|
||||
);
|
||||
var localDropoffAddressBox = Row(children: [
|
||||
FcsIDIcon(),
|
||||
Expanded(
|
||||
child: DisplayText(
|
||||
text: mainModel.setting.usaAddress,
|
||||
),
|
||||
)
|
||||
]);
|
||||
final createBtn = LocalButton(
|
||||
textKey: "shipment.create",
|
||||
callBack: _create,
|
||||
callBack: _save,
|
||||
);
|
||||
|
||||
final updateBtn = LocalButton(
|
||||
textKey: "shipment.update",
|
||||
callBack: _save,
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
@@ -205,6 +180,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
_isNew ? Container() : Center(child: shipmentNumberBox),
|
||||
LocalTitle(textKey: "shipment.type"),
|
||||
LocalRadioButtons(
|
||||
values: pickupModel.shipmentTypes,
|
||||
@@ -214,16 +190,28 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
_selectedShipmentType = v;
|
||||
});
|
||||
}),
|
||||
// handlingFeeBox,
|
||||
// shipmentTypeBox,
|
||||
LocalTitle(textKey: "shipment.location"),
|
||||
pickupAddressBox,
|
||||
LocalTitle(textKey: "shipment.date.time"),
|
||||
pickupDateBox,
|
||||
fromTimeBox,
|
||||
toTimeBox,
|
||||
// localDropoffAddress,
|
||||
// curierDropoffAddress,
|
||||
...(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,
|
||||
]
|
||||
: []),
|
||||
LocalTitle(
|
||||
textKey: "boxes.name",
|
||||
trailing: IconButton(
|
||||
@@ -232,7 +220,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
Box box = await Navigator.push(
|
||||
Carton box = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ShipmentBoxEditor()),
|
||||
@@ -252,11 +240,11 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> getBoxList(BuildContext context, List<Box> boxes) {
|
||||
List<Widget> getBoxList(BuildContext context, List<Carton> boxes) {
|
||||
return boxes.asMap().entries.map((_box) {
|
||||
return InkWell(
|
||||
onTap: () async {
|
||||
Box box = await Navigator.of(context).push(CupertinoPageRoute(
|
||||
Carton box = await Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => ShipmentBoxEditor(box: _box.value)));
|
||||
_saveBox(box);
|
||||
},
|
||||
@@ -267,7 +255,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
onTap: () => _removeBox(_box.value),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(Icons.remove, color: primaryColor),
|
||||
child: Icon(Icons.remove_circle, color: primaryColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -276,24 +264,25 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
_addBox(Box box) {
|
||||
_addBox(Carton box) {
|
||||
if (box == null) return;
|
||||
box.cartonType = carton_from_shipments;
|
||||
_shipment.boxes.add(box);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
_saveBox(Box box) {
|
||||
_saveBox(Carton box) {
|
||||
if (box == null) return;
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
_removeBox(Box box) {
|
||||
_removeBox(Carton box) {
|
||||
if (box == null) return;
|
||||
_shipment.boxes.remove(box);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
_create() async {
|
||||
_save() async {
|
||||
_shipment.shipmentType = this._selectedShipmentType;
|
||||
_shipment.pickupDate = dateFormatter.parse(_pickupDate.text);
|
||||
_shipment.pickupTimeStart = _fromTimeEditingController.text;
|
||||
@@ -307,9 +296,9 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
if (_isNew) {
|
||||
await shipmentModel.createShipment(_shipment);
|
||||
} else {
|
||||
await shipmentModel.createShipment(_shipment);
|
||||
await shipmentModel.updateShipment(_shipment);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
@@ -318,4 +307,9 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_openCourierWebsite() {
|
||||
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
|
||||
launch("${mainModel.setting.courierWebsite}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,14 +101,14 @@ class _ShipmentListState extends State<ShipmentList> {
|
||||
child: ListView.separated(
|
||||
controller: _controller,
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
color: Colors.black,
|
||||
color: Colors.grey,
|
||||
height: 1,
|
||||
),
|
||||
scrollDirection: Axis.vertical,
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
shrinkWrap: true,
|
||||
itemCount: shipmentModel.shipments.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return ShipmentListRow(
|
||||
key: ValueKey(shipmentModel.shipments[index].id),
|
||||
pickUp: shipmentModel.shipments[index]);
|
||||
}),
|
||||
onRefresh: () =>
|
||||
|
||||
@@ -1,49 +1,25 @@
|
||||
import 'package:fcs/domain/entities/shipment.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
|
||||
import '../main/util.dart';
|
||||
import 'shipment_editor.dart';
|
||||
import 'shipment_info.dart';
|
||||
|
||||
class ShipmentListRow extends StatefulWidget {
|
||||
class ShipmentListRow extends StatelessWidget {
|
||||
final Shipment pickUp;
|
||||
const ShipmentListRow({this.pickUp});
|
||||
|
||||
@override
|
||||
_ShipmentListRowState createState() => _ShipmentListRowState();
|
||||
}
|
||||
|
||||
class _ShipmentListRowState extends State<ShipmentListRow> {
|
||||
final double dotSize = 15.0;
|
||||
Shipment _pickUp = new Shipment();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// PickUpModel pickUpModel = Provider.of<PickUpModel>(context, listen: false);
|
||||
if (widget.pickUp != null) {
|
||||
_pickUp = widget.pickUp;
|
||||
// pickUpModel.pickups.forEach((b) {
|
||||
// if (widget.pickUp.id == b.id) {
|
||||
// _pickUp = b;
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
const ShipmentListRow({Key key, this.pickUp}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 15, right: 15),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => ShipmentInfo(shipment: _pickUp)));
|
||||
},
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => ShipmentInfo(shipment: pickUp)));
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(left: 15, right: 15),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
@@ -64,7 +40,7 @@ class _ShipmentListRowState extends State<ShipmentListRow> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
_pickUp.shipmentNumber,
|
||||
pickUp.shipmentNumber,
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.black),
|
||||
),
|
||||
@@ -72,9 +48,9 @@ class _ShipmentListRowState extends State<ShipmentListRow> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 10.0, top: 10),
|
||||
child: new Text(
|
||||
_pickUp.id == null
|
||||
pickUp.id == null
|
||||
? ''
|
||||
: "Last ${_pickUp.last} days",
|
||||
: "Last ${pickUp.last} days",
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.grey),
|
||||
),
|
||||
@@ -90,23 +66,23 @@ class _ShipmentListRowState extends State<ShipmentListRow> {
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(0),
|
||||
child: getStatus(_pickUp.currentStatus),
|
||||
child: getStatus(pickUp.currentStatus),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0, top: 5, bottom: 5),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
new Text(
|
||||
_pickUp.weight == null
|
||||
pickUp.weight == null
|
||||
? ''
|
||||
: _pickUp.weight.toString() + 'lb - ',
|
||||
: pickUp.weight.toString() + 'lb - ',
|
||||
style:
|
||||
new TextStyle(fontSize: 15.0, color: Colors.grey),
|
||||
),
|
||||
new Text(
|
||||
_pickUp.numberOfPackage == null
|
||||
pickUp.numberOfPackage == null
|
||||
? ""
|
||||
: _pickUp.numberOfPackage.toString() + ' packages',
|
||||
: pickUp.numberOfPackage.toString() + ' packages',
|
||||
style:
|
||||
new TextStyle(fontSize: 15.0, color: Colors.grey),
|
||||
),
|
||||
|
||||
24
lib/pages/shipment/widgets.dart
Normal file
24
lib/pages/shipment/widgets.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:fcs/domain/entities/shipment.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Widget getShipmentNumberStatus(BuildContext context, Shipment shipment) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
LocalText(
|
||||
context,
|
||||
'',
|
||||
text: shipment.shipmentNumber ?? "",
|
||||
color: primaryColor,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: Chip(label: Text(shipment.currentStatus ?? "")),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user