add paginator

This commit is contained in:
Sai Naw Wun
2020-10-16 10:58:31 +06:30
parent bcbcfd71ee
commit 0abe4ef73f
29 changed files with 953 additions and 703 deletions

View File

@@ -4,9 +4,7 @@ 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/delivery_address/model/delivery_address_model.dart';
import 'package:fcs/pages/main/model/main_model.dart';
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
import 'package:fcs/pages/widgets/bottom_up_page_route.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';
@@ -37,10 +35,8 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
Box _box;
bool _isLoading = false;
bool _isNew;
DeliveryAddress _deliveryAddress;
double volumetricRatio = 0;
double shipmentWeight = 0;
List<CargoType> cargos = [];
@override
void initState() {
@@ -52,22 +48,26 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
if (widget.box != null) {
_box = widget.box;
_deliveryAddress = _box.shippingAddress;
_isNew = false;
_lengthCtl.text = _box.length.toString();
_widthCtl.text = _box.width.toString();
_heightCtl.text = _box.height.toString();
} else {
var shipmentModel =
Provider.of<DeliveryAddressModel>(context, listen: false);
_deliveryAddress = shipmentModel.defalutAddress;
_isNew = true;
_box = Box();
_lengthCtl.text = "0";
_widthCtl.text = "0";
_heightCtl.text = "0";
_box = Box(cargoTypes: []);
_box.deliveryAddress = shipmentModel.defalutAddress;
_lengthCtl.text = "12";
_widthCtl.text = "12";
_heightCtl.text = "12";
}
_lengthCtl.addListener(_calShipmentWeight);
_widthCtl.addListener(_calShipmentWeight);
_heightCtl.addListener(_calShipmentWeight);
_calShipmentWeight();
}
_calShipmentWeight() {
@@ -75,7 +75,7 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
double w = double.parse(_widthCtl.text, (s) => 0);
double h = double.parse(_heightCtl.text, (s) => 0);
setState(() {
shipmentWeight = l * w * h / volumetricRatio;
shipmentWeight = (l * w * h / volumetricRatio).ceilToDouble();
});
}
@@ -113,6 +113,7 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
);
final createBtn = LocalButton(
textKey: "shipment.box.add",
callBack: _creatCarton,
);
return LocalProgress(
inAsyncCall: _isLoading,
@@ -182,19 +183,19 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
shipmentWeightBox,
LocalTitle(textKey: "shipment.box.delivery"),
DefaultDeliveryAddress(
deliveryAddress: _deliveryAddress,
deliveryAddress: _box.deliveryAddress,
labelKey: "shipment.box.delivery",
onTap: () async {
DeliveryAddress d = await Navigator.push<DeliveryAddress>(
context,
CupertinoPageRoute(
builder: (context) => DeliveryAddressSelection(
deliveryAddress: _deliveryAddress,
deliveryAddress: _box.deliveryAddress,
)),
);
if (d == null) return;
setState(() {
this._deliveryAddress = d;
_box.deliveryAddress = d;
});
}),
createBtn
@@ -206,11 +207,11 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
}
List<MyDataRow> getCargoRows(BuildContext context) {
if (cargos == null || cargos == null) {
if (_box.cargoTypes == null) {
return [];
}
int total = 0;
var rows = cargos.map((c) {
double total = 0;
var rows = _box.cargoTypes.map((c) {
total += c.weight;
return MyDataRow(
onSelectChanged: (bool selected) async {
@@ -258,7 +259,6 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
color: Colors.black87,
fontWeight: FontWeight.bold,
),
)),
MyDataCell(
Padding(
@@ -278,14 +278,24 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
_addCargo(CargoType cargo) {
if (cargo == null) return;
setState(() {
cargos.remove(cargo);
cargos.add(cargo);
_box.cargoTypes.remove(cargo);
_box.cargoTypes.add(cargo);
});
}
_removeCargo(CargoType cargo) {
setState(() {
cargos.remove(cargo);
_box.cargoTypes.remove(cargo);
});
}
_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);
}
}