2020-10-18 02:38:46 +06:30
|
|
|
import 'package:fcs/domain/entities/carton.dart';
|
2020-10-15 03:06:13 +06:30
|
|
|
import 'package:fcs/domain/entities/cargo_type.dart';
|
2020-10-13 07:50:25 +06:30
|
|
|
import 'package:fcs/domain/vo/delivery_address.dart';
|
|
|
|
|
import 'package:fcs/helpers/theme.dart';
|
2020-10-18 02:38:46 +06:30
|
|
|
import 'package:fcs/pages/carton/cargo_type_editor.dart';
|
2020-10-13 07:50:25 +06:30
|
|
|
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
|
2020-10-15 03:06:13 +06:30
|
|
|
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
|
2020-10-13 07:50:25 +06:30
|
|
|
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';
|
2020-10-14 01:51:53 +06:30
|
|
|
import 'package:fcs/pages/widgets/length_picker.dart';
|
2020-10-13 07:50:25 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_button.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
2020-10-14 01:51:53 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_title.dart';
|
2020-10-13 07:50:25 +06:30
|
|
|
import 'package:fcs/pages/widgets/my_data_table.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
2020-10-14 13:54:42 +06:30
|
|
|
import 'package:flutter/cupertino.dart';
|
2020-10-13 07:50:25 +06:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_icons/flutter_icons.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
class ShipmentBoxEditor extends StatefulWidget {
|
2020-10-18 02:38:46 +06:30
|
|
|
final Carton box;
|
2020-10-13 07:50:25 +06:30
|
|
|
ShipmentBoxEditor({this.box});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_ShipmentBoxEditorState createState() => _ShipmentBoxEditorState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
|
|
|
|
TextEditingController _lengthCtl = new TextEditingController();
|
|
|
|
|
TextEditingController _widthCtl = new TextEditingController();
|
|
|
|
|
TextEditingController _heightCtl = new TextEditingController();
|
|
|
|
|
|
2020-10-18 02:38:46 +06:30
|
|
|
Carton _box;
|
2020-10-13 07:50:25 +06:30
|
|
|
bool _isLoading = false;
|
|
|
|
|
bool _isNew;
|
2020-10-14 01:51:53 +06:30
|
|
|
double volumetricRatio = 0;
|
|
|
|
|
double shipmentWeight = 0;
|
2020-10-13 07:50:25 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
|
2020-10-15 03:06:13 +06:30
|
|
|
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
|
|
|
|
|
.rate
|
|
|
|
|
.volumetricRatio;
|
2020-10-13 07:50:25 +06:30
|
|
|
|
|
|
|
|
if (widget.box != null) {
|
|
|
|
|
_box = widget.box;
|
|
|
|
|
_isNew = false;
|
2020-10-16 10:58:31 +06:30
|
|
|
_lengthCtl.text = _box.length.toString();
|
|
|
|
|
_widthCtl.text = _box.width.toString();
|
|
|
|
|
_heightCtl.text = _box.height.toString();
|
2020-10-13 07:50:25 +06:30
|
|
|
} else {
|
|
|
|
|
var shipmentModel =
|
|
|
|
|
Provider.of<DeliveryAddressModel>(context, listen: false);
|
|
|
|
|
|
|
|
|
|
_isNew = true;
|
2020-10-18 02:38:46 +06:30
|
|
|
_box = Carton(cargoTypes: []);
|
2020-10-16 10:58:31 +06:30
|
|
|
_box.deliveryAddress = shipmentModel.defalutAddress;
|
|
|
|
|
|
|
|
|
|
_lengthCtl.text = "12";
|
|
|
|
|
_widthCtl.text = "12";
|
|
|
|
|
_heightCtl.text = "12";
|
2020-10-13 07:50:25 +06:30
|
|
|
}
|
|
|
|
|
_lengthCtl.addListener(_calShipmentWeight);
|
|
|
|
|
_widthCtl.addListener(_calShipmentWeight);
|
|
|
|
|
_heightCtl.addListener(_calShipmentWeight);
|
2020-10-16 10:58:31 +06:30
|
|
|
_calShipmentWeight();
|
2020-10-13 07:50:25 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_calShipmentWeight() {
|
|
|
|
|
double l = double.parse(_lengthCtl.text, (s) => 0);
|
|
|
|
|
double w = double.parse(_widthCtl.text, (s) => 0);
|
|
|
|
|
double h = double.parse(_heightCtl.text, (s) => 0);
|
|
|
|
|
setState(() {
|
2020-10-16 10:58:31 +06:30
|
|
|
shipmentWeight = (l * w * h / volumetricRatio).ceilToDouble();
|
2020-10-13 07:50:25 +06:30
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final shipmentWeightBox = DisplayText(
|
|
|
|
|
labelTextKey: "shipment.box.shipment.weight",
|
|
|
|
|
text: shipmentWeight == null ? "" : shipmentWeight.toStringAsFixed(0),
|
|
|
|
|
iconData: MaterialCommunityIcons.weight,
|
|
|
|
|
);
|
2020-10-14 01:51:53 +06:30
|
|
|
|
|
|
|
|
final lengthBox = LengthPicker(
|
2020-10-13 07:50:25 +06:30
|
|
|
controller: _lengthCtl,
|
2020-10-14 01:51:53 +06:30
|
|
|
lableKey: "shipment.box.length",
|
2020-10-13 07:50:25 +06:30
|
|
|
);
|
2020-10-14 01:51:53 +06:30
|
|
|
final widthBox = LengthPicker(
|
2020-10-13 07:50:25 +06:30
|
|
|
controller: _widthCtl,
|
2020-10-14 01:51:53 +06:30
|
|
|
lableKey: "shipment.box.width",
|
2020-10-13 07:50:25 +06:30
|
|
|
);
|
2020-10-14 01:51:53 +06:30
|
|
|
final heightBox = LengthPicker(
|
2020-10-13 07:50:25 +06:30
|
|
|
controller: _heightCtl,
|
2020-10-14 01:51:53 +06:30
|
|
|
lableKey: "shipment.box.height",
|
|
|
|
|
);
|
|
|
|
|
final dimBox = Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
|
|
|
child: Icon(FontAwesome.arrow_circle_right, color: primaryColor),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(child: lengthBox, width: 80),
|
|
|
|
|
SizedBox(child: widthBox, width: 80),
|
|
|
|
|
SizedBox(child: heightBox, width: 80),
|
|
|
|
|
],
|
2020-10-13 07:50:25 +06:30
|
|
|
);
|
|
|
|
|
final createBtn = LocalButton(
|
|
|
|
|
textKey: "shipment.box.add",
|
2020-10-16 10:58:31 +06:30
|
|
|
callBack: _creatCarton,
|
2020-10-13 07:50:25 +06:30
|
|
|
);
|
|
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
centerTitle: true,
|
|
|
|
|
leading: new IconButton(
|
|
|
|
|
icon: new Icon(
|
2020-10-14 13:54:42 +06:30
|
|
|
CupertinoIcons.back,
|
2020-10-13 07:50:25 +06:30
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
|
),
|
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
title: LocalText(
|
|
|
|
|
context,
|
2020-10-14 13:17:12 +06:30
|
|
|
_isNew ? "boxes.create.title" : "box.edit.title",
|
2020-10-13 07:50:25 +06:30
|
|
|
fontSize: 20,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
body: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
child: ListView(
|
|
|
|
|
children: [
|
2020-10-14 01:51:53 +06:30
|
|
|
LocalTitle(
|
|
|
|
|
textKey: "shipment.box.cargo.type",
|
|
|
|
|
trailing: IconButton(
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.add_circle,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
onPressed: () async {
|
2020-10-15 03:06:13 +06:30
|
|
|
CargoType cargo = await Navigator.push<CargoType>(
|
2020-10-14 13:54:42 +06:30
|
|
|
context,
|
|
|
|
|
CupertinoPageRoute(
|
|
|
|
|
builder: (context) => CargoTypeEditor()));
|
2020-10-14 01:51:53 +06:30
|
|
|
_addCargo(cargo);
|
|
|
|
|
}),
|
|
|
|
|
),
|
2020-10-13 07:50:25 +06:30
|
|
|
MyDataTable(
|
|
|
|
|
headingRowHeight: 40,
|
|
|
|
|
columns: [
|
|
|
|
|
MyDataColumn(
|
|
|
|
|
label: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
"cargo.type",
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
MyDataColumn(
|
|
|
|
|
label: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
"cargo.weight",
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
rows: getCargoRows(context),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 30,
|
|
|
|
|
),
|
2020-10-14 01:51:53 +06:30
|
|
|
LocalTitle(textKey: "shipment.box.dimemsion"),
|
|
|
|
|
dimBox,
|
2020-10-13 07:50:25 +06:30
|
|
|
shipmentWeightBox,
|
2020-10-14 01:51:53 +06:30
|
|
|
LocalTitle(textKey: "shipment.box.delivery"),
|
2020-10-13 07:50:25 +06:30
|
|
|
DefaultDeliveryAddress(
|
2020-10-16 10:58:31 +06:30
|
|
|
deliveryAddress: _box.deliveryAddress,
|
2020-10-14 16:53:16 +06:30
|
|
|
labelKey: "shipment.box.delivery",
|
2020-10-13 07:50:25 +06:30
|
|
|
onTap: () async {
|
|
|
|
|
DeliveryAddress d = await Navigator.push<DeliveryAddress>(
|
|
|
|
|
context,
|
2020-10-14 13:54:42 +06:30
|
|
|
CupertinoPageRoute(
|
|
|
|
|
builder: (context) => DeliveryAddressSelection(
|
2020-10-16 10:58:31 +06:30
|
|
|
deliveryAddress: _box.deliveryAddress,
|
2020-10-14 13:54:42 +06:30
|
|
|
)),
|
2020-10-13 07:50:25 +06:30
|
|
|
);
|
|
|
|
|
if (d == null) return;
|
|
|
|
|
setState(() {
|
2020-10-16 10:58:31 +06:30
|
|
|
_box.deliveryAddress = d;
|
2020-10-13 07:50:25 +06:30
|
|
|
});
|
|
|
|
|
}),
|
|
|
|
|
createBtn
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<MyDataRow> getCargoRows(BuildContext context) {
|
2020-10-16 10:58:31 +06:30
|
|
|
if (_box.cargoTypes == null) {
|
2020-10-13 07:50:25 +06:30
|
|
|
return [];
|
|
|
|
|
}
|
2020-10-16 10:58:31 +06:30
|
|
|
double total = 0;
|
|
|
|
|
var rows = _box.cargoTypes.map((c) {
|
2020-10-13 07:50:25 +06:30
|
|
|
total += c.weight;
|
|
|
|
|
return MyDataRow(
|
2020-10-14 01:51:53 +06:30
|
|
|
onSelectChanged: (bool selected) async {
|
2020-10-15 03:06:13 +06:30
|
|
|
CargoType cargo = await Navigator.push<CargoType>(
|
2020-10-14 01:51:53 +06:30
|
|
|
context,
|
2020-10-14 13:54:42 +06:30
|
|
|
CupertinoPageRoute(
|
|
|
|
|
builder: (context) => CargoTypeEditor(
|
|
|
|
|
cargo: c,
|
|
|
|
|
)));
|
2020-10-14 01:51:53 +06:30
|
|
|
_addCargo(cargo);
|
|
|
|
|
},
|
2020-10-13 07:50:25 +06:30
|
|
|
cells: [
|
|
|
|
|
MyDataCell(new Text(
|
2020-10-15 03:06:13 +06:30
|
|
|
c.name == null ? "" : c.name,
|
2020-10-13 07:50:25 +06:30
|
|
|
style: textStyle,
|
|
|
|
|
)),
|
|
|
|
|
MyDataCell(
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
Text(c.weight == null ? "0" : c.weight.toString(),
|
|
|
|
|
style: textStyle),
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.remove_circle,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
2020-10-14 01:51:53 +06:30
|
|
|
onPressed: () => {_removeCargo(c)},
|
2020-10-13 07:50:25 +06:30
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}).toList();
|
|
|
|
|
|
|
|
|
|
var totalRow = MyDataRow(
|
|
|
|
|
onSelectChanged: (bool selected) {},
|
|
|
|
|
cells: [
|
|
|
|
|
MyDataCell(Align(
|
|
|
|
|
alignment: Alignment.centerRight,
|
2020-10-15 17:33:43 +06:30
|
|
|
child: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
"shipment.cargo.total",
|
|
|
|
|
color: Colors.black87,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
2020-10-13 07:50:25 +06:30
|
|
|
)),
|
|
|
|
|
MyDataCell(
|
|
|
|
|
Padding(
|
2020-10-15 17:33:43 +06:30
|
|
|
padding: const EdgeInsets.only(right: 48.0),
|
2020-10-13 07:50:25 +06:30
|
|
|
child: Align(
|
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
|
child: Text(total.toString(),
|
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold))),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
rows.add(totalRow);
|
|
|
|
|
return rows;
|
|
|
|
|
}
|
2020-10-14 01:51:53 +06:30
|
|
|
|
2020-10-15 03:06:13 +06:30
|
|
|
_addCargo(CargoType cargo) {
|
2020-10-14 01:51:53 +06:30
|
|
|
if (cargo == null) return;
|
|
|
|
|
setState(() {
|
2020-10-16 10:58:31 +06:30
|
|
|
_box.cargoTypes.remove(cargo);
|
|
|
|
|
_box.cargoTypes.add(cargo);
|
2020-10-14 01:51:53 +06:30
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-15 03:06:13 +06:30
|
|
|
_removeCargo(CargoType cargo) {
|
2020-10-14 01:51:53 +06:30
|
|
|
setState(() {
|
2020-10-16 10:58:31 +06:30
|
|
|
_box.cargoTypes.remove(cargo);
|
2020-10-14 01:51:53 +06:30
|
|
|
});
|
|
|
|
|
}
|
2020-10-16 10:58:31 +06:30
|
|
|
|
|
|
|
|
_creatCarton() {
|
|
|
|
|
double l = double.parse(_lengthCtl.text, (s) => 0);
|
|
|
|
|
double w = double.parse(_widthCtl.text, (s) => 0);
|
|
|
|
|
double h = double.parse(_heightCtl.text, (s) => 0);
|
|
|
|
|
_box.length = l;
|
|
|
|
|
_box.width = w;
|
|
|
|
|
_box.height = h;
|
|
|
|
|
Navigator.pop(context, _box);
|
|
|
|
|
}
|
2020-10-13 07:50:25 +06:30
|
|
|
}
|