add carton api
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
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';
|
||||
@@ -10,6 +11,7 @@ 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_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';
|
||||
@@ -18,11 +20,13 @@ 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';
|
||||
|
||||
import 'carton_cargo_table.dart';
|
||||
import 'carton_editor.dart';
|
||||
import 'carton_mix_table.dart';
|
||||
import 'carton_package_table.dart';
|
||||
import 'model/carton_model.dart';
|
||||
import 'widgets.dart';
|
||||
|
||||
final DateFormat dateFormat = DateFormat("d MMM yyyy");
|
||||
|
||||
@@ -38,7 +42,6 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
bool _isLoading = false;
|
||||
Carton _box;
|
||||
String _selectedCartonType;
|
||||
String _shipmentNumber;
|
||||
List<Package> _packages = [];
|
||||
List<Carton> _mixBoxes = [];
|
||||
Carton _selectedShipmentBox = new Carton();
|
||||
@@ -50,35 +53,16 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
double volumetricRatio = 0;
|
||||
double shipmentWeight = 0;
|
||||
|
||||
bool isMixBox;
|
||||
bool isFromShipments;
|
||||
bool isFromPackage;
|
||||
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 boxModel = Provider.of<CartonModel>(context, listen: false);
|
||||
_selectedShipmentBox = boxModel.boxeList[0];
|
||||
|
||||
//for mix boxes
|
||||
_mixBoxes = [
|
||||
boxModel.boxeList[0],
|
||||
boxModel.boxeList[1],
|
||||
boxModel.boxeList[2]
|
||||
];
|
||||
_mixBoxes.forEach((b) {
|
||||
b.isChecked = false;
|
||||
});
|
||||
|
||||
//for shipment weight
|
||||
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
|
||||
@@ -94,6 +78,34 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
|
||||
_cargoTypes = _box.cargoTypes;
|
||||
_deliveryAddress = _box.deliveryAddress;
|
||||
|
||||
isMixBox = _box.cartonType == carton_mix_box;
|
||||
isFromShipments = _box.cartonType == carton_from_shipments;
|
||||
isFromPackage = _box.cartonType == carton_from_packages;
|
||||
isEdiable =
|
||||
(isMixBox || isFromPackage) && _box.status == carton_packed_status;
|
||||
|
||||
if (isFromPackage) {
|
||||
_loadPackages();
|
||||
}
|
||||
}
|
||||
|
||||
_loadPackages() async {
|
||||
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);
|
||||
packages.forEach((p) {
|
||||
if (_box.packageIDs.contains(p.id)) {
|
||||
p.isChecked = true;
|
||||
} else {
|
||||
p.isChecked = false;
|
||||
}
|
||||
});
|
||||
|
||||
setState(() {
|
||||
_box.packages = packages;
|
||||
});
|
||||
}
|
||||
|
||||
_calShipmentWeight() {
|
||||
@@ -111,64 +123,18 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
}
|
||||
|
||||
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,
|
||||
);
|
||||
@@ -184,60 +150,6 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
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(
|
||||
@@ -270,139 +182,6 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
),
|
||||
);
|
||||
|
||||
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",
|
||||
@@ -437,6 +216,9 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
labelTextKey: "box.shipment_weight",
|
||||
iconData: MaterialCommunityIcons.weight,
|
||||
);
|
||||
final cargoTableBox = CargoTable(
|
||||
cargoTypes: _box.cargoTypes,
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
@@ -455,12 +237,18 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
fontSize: 20,
|
||||
color: primaryColor,
|
||||
),
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(Icons.edit, color: primaryColor),
|
||||
onPressed: _gotoEditor,
|
||||
),
|
||||
],
|
||||
actions: isEdiable
|
||||
? <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(Icons.edit, color: primaryColor),
|
||||
onPressed: _gotoEditor,
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete, color: primaryColor),
|
||||
onPressed: _delete,
|
||||
),
|
||||
]
|
||||
: [],
|
||||
),
|
||||
body: Card(
|
||||
child: Column(
|
||||
@@ -469,30 +257,21 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: ListView(children: <Widget>[
|
||||
// Center(child: nameWidget(_box.packageNumber)),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
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(),
|
||||
),
|
||||
],
|
||||
isFromPackage
|
||||
? CartonPackageTable(
|
||||
packages: _box.packages,
|
||||
)
|
||||
: _selectedCartonType == "From shipments"
|
||||
: Container(),
|
||||
isFromPackage
|
||||
? Container()
|
||||
: isFromShipments
|
||||
? Column(
|
||||
children: [
|
||||
LocalTitle(textKey: "box.shipment.boxes"),
|
||||
@@ -504,27 +283,17 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
],
|
||||
)
|
||||
: _selectedCartonType == "Mix carton"
|
||||
? Column(
|
||||
children: [
|
||||
LocalTitle(textKey: "box.shipment.boxes"),
|
||||
mixBoxTitle,
|
||||
Divider(
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
Column(
|
||||
children: getMixBoxRowList(),
|
||||
)
|
||||
],
|
||||
? CartonMixTable(
|
||||
cartons: _box.cartons,
|
||||
onSelect: (c, check) {
|
||||
setState(() {
|
||||
c.isChecked = check;
|
||||
});
|
||||
},
|
||||
)
|
||||
: Container(),
|
||||
LocalTitle(textKey: "box.cargo_type"),
|
||||
cargoTitle,
|
||||
Divider(
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
Column(
|
||||
children: getCargoRowList(),
|
||||
),
|
||||
LocalTitle(textKey: "box.cargo.type"),
|
||||
cargoTableBox,
|
||||
LocalTitle(textKey: "box.dimension"),
|
||||
dimBox,
|
||||
shipmentWeightBox,
|
||||
@@ -533,12 +302,6 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
deliveryAddress: _deliveryAddress,
|
||||
labelKey: "box.delivery_address",
|
||||
),
|
||||
LocalTitle(textKey: "box.status"),
|
||||
Container(
|
||||
height: 230,
|
||||
child: Timeline(
|
||||
children: _models(), position: TimelinePosition.Left),
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
)
|
||||
@@ -552,9 +315,40 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
}
|
||||
|
||||
_gotoEditor() async {
|
||||
Navigator.push(
|
||||
bool updated = await Navigator.push<bool>(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => CartonEditor(box: widget.box)),
|
||||
);
|
||||
if (updated ?? false) {
|
||||
var cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
var c = await cartonModel.getCarton(widget.box.id);
|
||||
setState(() {
|
||||
_box = c;
|
||||
});
|
||||
_loadPackages();
|
||||
}
|
||||
}
|
||||
|
||||
_delete() {
|
||||
showConfirmDialog(context, "box.delete.confirm", () {
|
||||
_deleteCarton();
|
||||
});
|
||||
}
|
||||
|
||||
_deleteCarton() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
var cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
await cartonModel.deleteCarton(widget.box);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user