add delivery

This commit is contained in:
Sai Naw Wun
2020-10-21 05:40:58 +06:30
parent 9aefc585ec
commit b367478f52
14 changed files with 189 additions and 745 deletions

View File

@@ -1,8 +1,11 @@
import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/domain/constants.dart';
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/domain/entities/package.dart';
import 'package:fcs/domain/vo/delivery_address.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/carton/carton_package_table.dart';
import 'package:fcs/pages/carton/model/carton_model.dart';
import 'package:fcs/pages/carton/widgets.dart';
import 'package:fcs/pages/delivery/model/delivery_model.dart';
import 'package:fcs/pages/main/util.dart';
@@ -12,6 +15,8 @@ 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';
import 'package:fcs/pages/widgets/length_picker.dart';
import 'package:fcs/pages/widgets/local_button.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/progress.dart';
@@ -20,8 +25,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:timeline_list/timeline.dart';
import 'package:timeline_list/timeline_model.dart';
final DateFormat dateFormat = DateFormat("d MMM yyyy");
@@ -37,7 +40,6 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
bool _isLoading = false;
Carton _box;
String _selectedCartonType;
String _shipmentNumber;
List<Package> _packages = [];
List<Carton> _mixBoxes = [];
Carton _selectedShipmentBox = new Carton();
@@ -49,35 +51,17 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
double volumetricRatio = 0;
double shipmentWeight = 0;
bool isMixBox;
bool isFromShipments;
bool isFromPackages;
bool isSmallBag;
bool isEdiable;
@override
void initState() {
super.initState();
_box = widget.box;
_shipmentNumber = _box.shipmentNumber;
_selectedCartonType = _box.cartonType;
// for packages
var packageModel = Provider.of<PackageModel>(context, listen: false);
_packages = [
// packageModel.packages[0],
// packageModel.packages[1],
];
_packages.forEach((p) {
p.isChecked = false;
});
//for shipment boxes
var deliveryModel = Provider.of<DeliveryModel>(context, listen: false);
_selectedShipmentBox = deliveryModel.cartonList[0];
//for mix carton
_mixBoxes = [
deliveryModel.cartonList[0],
deliveryModel.cartonList[1],
deliveryModel.cartonList[2]
];
_mixBoxes.forEach((b) {
b.isChecked = false;
});
//for shipment weight
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
@@ -87,12 +71,44 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
_widthController.addListener(_calShipmentWeight);
_heightController.addListener(_calShipmentWeight);
_updateBoxData();
_loadPackages();
}
_updateBoxData() {
_widthController.text = _box.width.toString();
_heightController.text = _box.height.toString();
_lengthController.text = _box.length.toString();
_cargoTypes = _box.cargoTypes;
_deliveryAddress = _box.deliveryAddress;
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);
List<Package> packages = await packageModel.getPackages(_box.userID, [
package_processed_status,
package_packed_status,
package_shipped_status
]);
packages = packages.where((p) => _box.packageIDs.contains(p.id)).toList();
packages.forEach((p) {
p.isChecked = true;
});
setState(() {
_box.packages = packages;
});
}
_calShipmentWeight() {
@@ -110,64 +126,18 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
}
final DateFormat dateFormat = DateFormat("d MMM yyyy");
List<TimelineModel> _models() {
if (_box.shipmentHistory == null) return [];
// return [];
return _box.shipmentHistory
.map((e) => TimelineModel(
Padding(
padding: const EdgeInsets.all(18.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(e.status,
style: TextStyle(
color: e.done ? primaryColor : Colors.grey,
fontSize: 16,
fontWeight: FontWeight.bold)),
e.status == "Processed"
? Text("(Waiting for payment)",
style: TextStyle(
color: e.done ? primaryColor : Colors.grey,
fontSize: 14,
fontWeight: FontWeight.bold))
: Container(),
Text(dateFormat.format(e.date)),
],
),
),
iconBackground: e.done ? primaryColor : Colors.grey,
icon: Icon(
e.status == "Shipped"
? Ionicons.ios_airplane
: e.status == "Delivered"
? MaterialCommunityIcons.truck_fast
: e.status == "Processed"
? MaterialIcons.check
: Octicons.package,
color: Colors.white,
)))
.toList();
}
@override
Widget build(BuildContext context) {
final cargoType = Container(
height: 30,
padding: EdgeInsets.only(left: 15),
child: Row(
children: [
Icon(Icons.check_circle, color: primaryColor),
SizedBox(
width: 10,
),
Text(_selectedCartonType ?? ""),
],
),
);
var cartonModel = Provider.of<CartonModel>(context);
final cartonTypeBox = LocalRadioButtons(
readOnly: true,
values: cartonModel.cartonTypesInfo,
selectedValue:
_box.isShipmentCarton ? carton_from_shipments : _box.cartonType);
final shipmentBox = DisplayText(
text: _shipmentNumber == null ? "" : _shipmentNumber,
text: _box.fcsShipmentNumber,
labelTextKey: "box.fcs_shipment_num",
iconData: Ionicons.ios_airplane,
);
@@ -183,60 +153,6 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
iconData: Icons.person,
);
final packageTitle = Container(
padding: EdgeInsets.only(left: 15, right: 10.0, top: 20),
child: Row(
children: <Widget>[
Expanded(
child: LocalText(context, 'box.tracking.id', color: Colors.grey),
),
LocalText(context, 'box.package.desc', color: Colors.grey),
],
),
);
List<Widget> getPackageRowList() {
return _packages.asMap().entries.map((p) {
return Container(
color: Colors.grey[50].withOpacity(0.2),
child: Container(
padding:
EdgeInsets.only(left: 15.0, right: 10.0, top: 5.0, bottom: 5.0),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: p.key == _packages.length - 1
? Colors.white
: Colors.grey[350],
width: 1),
),
),
child: Row(
children: <Widget>[
Expanded(
child: new Text(
p.value.trackingID,
style: textStyle,
)),
new Column(
children: [
new Text(
p.value.desc == null ? "" : p.value.desc,
style: textStyle,
),
new Text(
"(${p.value.market == null ? "" : p.value.market})",
style: textStyle,
)
],
)
],
),
),
);
}).toList();
}
final shipmentBoxTitle = Container(
padding: EdgeInsets.only(left: 15, right: 10.0, top: 20),
child: Row(
@@ -269,139 +185,6 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
),
);
final mixBoxTitle = Container(
padding: EdgeInsets.only(left: 15, right: 10.0, top: 20),
child: Row(
children: <Widget>[
Expanded(
child: LocalText(context, 'box.mix.number', color: Colors.grey),
),
LocalText(context, 'box.mix.desc', color: Colors.grey),
],
),
);
List<Widget> getMixBoxRowList() {
return _mixBoxes.asMap().entries.map((b) {
return Container(
color: Colors.grey[50].withOpacity(0.2),
child: Container(
padding: EdgeInsets.only(
left: 15.0, right: 10.0, top: 13.0, bottom: 13.0),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: b.key == _mixBoxes.length - 1
? Colors.white
: Colors.grey[350],
width: 1),
),
),
child: Row(
children: <Widget>[
Expanded(
child: new Text(
b.value.packageNumber,
style: textStyle,
)),
new Text(
b.value.desc == null ? "" : b.value.desc,
style: textStyle,
),
],
),
),
);
}).toList();
}
final cargoTitle = Container(
padding: EdgeInsets.only(left: 15, right: 0.0, top: 20),
child: Row(
children: <Widget>[
Expanded(
child: LocalText(context, 'cargo.type', color: Colors.grey),
),
Container(
padding: EdgeInsets.only(right: 10),
child: LocalText(context, 'cargo.weight', color: Colors.grey)),
],
),
);
List<Widget> getCargoRowList() {
if (_cargoTypes == null) {
return [];
}
double total = 0;
var rows = _cargoTypes.asMap().entries.map((c) {
total += c.value.weight;
return InkWell(
onTap: () {},
child: Container(
color: Colors.grey[50].withOpacity(0.2),
child: Container(
padding: EdgeInsets.only(
left: 15.0, right: 10.0, top: 13.0, bottom: 13.0),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.grey[350], width: 1),
),
),
child: Row(
children: <Widget>[
Expanded(
child: new Text(
c.value.name,
style: textStyle,
)),
Container(
padding: EdgeInsets.only(right: 10),
child: new Text(
c.value.weight == null ? "0" : c.value.weight.toString(),
style: textStyle,
),
)
],
),
),
),
);
}).toList();
var totalRow = InkWell(
child: Container(
color: Colors.grey[50].withOpacity(0.2),
child: Container(
padding:
EdgeInsets.only(left: 15.0, right: 10.0, top: 15.0, bottom: 15.0),
child: Row(
children: <Widget>[
Expanded(
child: new Text(
"Total Weight",
style: TextStyle(fontWeight: FontWeight.bold),
)),
Padding(
padding: const EdgeInsets.only(right: 10.0),
child: Align(
alignment: Alignment.centerRight,
child: new Text(
total.toString(),
style: TextStyle(fontWeight: FontWeight.bold),
),
),
)
],
),
),
));
rows.add(totalRow);
return rows;
}
final lengthBox = LengthPicker(
controller: _lengthController,
lableKey: "box.length",
@@ -436,6 +219,15 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
labelTextKey: "box.shipment_weight",
iconData: MaterialCommunityIcons.weight,
);
final mixCartonNumberBox = DisplayText(
text: _box.mixCartonNumber,
labelTextKey: "box.mix.carton",
iconData: MaterialCommunityIcons.package,
);
final deliverBtn = LocalButton(
textKey: "delivery.deliver.btn",
callBack: _deliver,
);
return LocalProgress(
inAsyncCall: _isLoading,
@@ -454,83 +246,38 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
fontSize: 20,
color: primaryColor,
),
// actions: <Widget>[
// IconButton(
// icon: Icon(Icons.edit, color: primaryColor),
// onPressed: _gotoEditor,
// ),
// ],
),
body: Padding(
padding: const EdgeInsets.all(10.0),
child: ListView(children: <Widget>[
Center(child: getCartonNumberStatus(context, _box)),
LocalTitle(textKey: "box.type.title"),
cargoType,
cartonTypeBox,
LocalTitle(textKey: "box.shipment_info"),
shipmentBox,
fcsIDBox,
customerNameBox,
_selectedCartonType == "From packages"
? Column(
children: [
LocalTitle(textKey: "box.packages"),
packageTitle,
Divider(
color: Colors.grey[400],
),
Column(
children: getPackageRowList(),
),
],
isSmallBag ? mixCartonNumberBox : Container(),
isMixBox ? Container() : fcsIDBox,
isMixBox ? Container() : customerNameBox,
isFromPackages || isSmallBag
? CartonPackageTable(
packages: _box.packages,
)
: _selectedCartonType == "From shipments"
? Column(
children: [
LocalTitle(textKey: "box.shipment.boxes"),
shipmentBoxTitle,
Divider(
color: Colors.grey[400],
),
shipmentBoxRow
],
)
: _selectedCartonType == "Mix carton"
? Column(
children: [
LocalTitle(textKey: "box.shipment.boxes"),
mixBoxTitle,
Divider(
color: Colors.grey[400],
),
Column(
children: getMixBoxRowList(),
)
],
)
: Container(),
LocalTitle(textKey: "box.cargo_type"),
cargoTitle,
Divider(
color: Colors.grey[400],
),
Column(
children: getCargoRowList(),
),
LocalTitle(textKey: "box.dimension"),
dimBox,
shipmentWeightBox,
LocalTitle(textKey: "box.delivery_address"),
DefaultDeliveryAddress(
deliveryAddress: _deliveryAddress,
labelKey: "box.delivery_address",
),
LocalTitle(textKey: "box.status"),
Container(
height: 230,
child: Timeline(
children: _models(), position: TimelinePosition.Left),
: Container(),
isMixBox
? Container()
: LocalTitle(textKey: "box.delivery_address"),
isMixBox
? Container()
: DefaultDeliveryAddress(
deliveryAddress: _deliveryAddress,
labelKey: "box.delivery_address",
),
SizedBox(
height: 20,
),
!isMixBox && _box.status == carton_shipped_status
? deliverBtn
: Container(),
SizedBox(
height: 20,
)
@@ -540,5 +287,26 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
);
}
_gotoEditor() async {}
_deliver() {
showConfirmDialog(context, "delivery.deliver.confirm", () {
_deliverCarton();
});
}
_deliverCarton() async {
setState(() {
_isLoading = true;
});
try {
var deliveryModel = Provider.of<DeliveryModel>(context, listen: false);
await deliveryModel.deliver(widget.box);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
}