add length picker
This commit is contained in:
@@ -1,23 +1,20 @@
|
||||
import 'package:fcs/domain/entities/box.dart';
|
||||
import 'package:fcs/domain/entities/cargo.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/box/cargo_type_editor.dart';
|
||||
import 'package:fcs/pages/delivery_address/delivery_address_list.dart';
|
||||
import 'package:fcs/pages/delivery_address/delivery_address_row.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/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';
|
||||
import 'package:fcs/pages/widgets/input_text.dart';
|
||||
import 'package:fcs/pages/widgets/length_picker.dart';
|
||||
import 'package:fcs/pages/widgets/local_button.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_title.dart';
|
||||
import 'package:fcs/pages/widgets/my_data_table.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:fcs/pages/widgets/title_with_add_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -38,11 +35,10 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
Box _box;
|
||||
bool _isLoading = false;
|
||||
bool _isNew;
|
||||
bool isMixBox = false;
|
||||
DeliveryAddress _deliveryAddress = new DeliveryAddress();
|
||||
double volumetricRatio;
|
||||
double shipmentWeight;
|
||||
List<Cargo> cargos;
|
||||
DeliveryAddress _deliveryAddress;
|
||||
double volumetricRatio = 0;
|
||||
double shipmentWeight = 0;
|
||||
List<Cargo> cargos = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -50,13 +46,10 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
|
||||
volumetricRatio =
|
||||
Provider.of<MainModel>(context, listen: false).setting.volumetricRatio;
|
||||
shipmentWeight = 0;
|
||||
cargos = [];
|
||||
|
||||
if (widget.box != null) {
|
||||
_box = widget.box;
|
||||
_deliveryAddress = _box.shippingAddress;
|
||||
|
||||
_isNew = false;
|
||||
} else {
|
||||
var shipmentModel =
|
||||
@@ -65,6 +58,9 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
|
||||
_isNew = true;
|
||||
_box = Box();
|
||||
_lengthCtl.text = "0";
|
||||
_widthCtl.text = "0";
|
||||
_heightCtl.text = "0";
|
||||
}
|
||||
_lengthCtl.addListener(_calShipmentWeight);
|
||||
_widthCtl.addListener(_calShipmentWeight);
|
||||
@@ -75,6 +71,7 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
double l = double.parse(_lengthCtl.text, (s) => 0);
|
||||
double w = double.parse(_widthCtl.text, (s) => 0);
|
||||
double h = double.parse(_heightCtl.text, (s) => 0);
|
||||
print("$l $w $h");
|
||||
setState(() {
|
||||
shipmentWeight = l * w * h / volumetricRatio;
|
||||
});
|
||||
@@ -82,30 +79,35 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
double iconSize = 32;
|
||||
|
||||
final shipmentWeightBox = DisplayText(
|
||||
labelTextKey: "shipment.box.shipment.weight",
|
||||
text: shipmentWeight == null ? "" : shipmentWeight.toStringAsFixed(0),
|
||||
iconData: MaterialCommunityIcons.weight,
|
||||
);
|
||||
final lengthBox = InputText(
|
||||
labelTextKey: "shipment.box.length",
|
||||
|
||||
final lengthBox = LengthPicker(
|
||||
controller: _lengthCtl,
|
||||
textInputType: TextInputType.number,
|
||||
iconData: FontAwesome.arrow_circle_right,
|
||||
lableKey: "shipment.box.length",
|
||||
);
|
||||
final widthBox = InputText(
|
||||
labelTextKey: "shipment.box.width",
|
||||
final widthBox = LengthPicker(
|
||||
controller: _widthCtl,
|
||||
textInputType: TextInputType.number,
|
||||
iconData: FontAwesome.arrow_circle_left,
|
||||
lableKey: "shipment.box.width",
|
||||
);
|
||||
final heightBox = InputText(
|
||||
labelTextKey: "shipment.box.height",
|
||||
final heightBox = LengthPicker(
|
||||
controller: _heightCtl,
|
||||
textInputType: TextInputType.number,
|
||||
iconData: FontAwesome.arrow_circle_up,
|
||||
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),
|
||||
],
|
||||
);
|
||||
final createBtn = LocalButton(
|
||||
textKey: "shipment.box.add",
|
||||
@@ -135,18 +137,19 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ListView(
|
||||
children: [
|
||||
TitleWithAddButton(
|
||||
iconData: MaterialCommunityIcons.briefcase_check,
|
||||
titleKey: "shipment.box.cargo.type",
|
||||
onTap: () async {
|
||||
Cargo cargo = await Navigator.push<Cargo>(
|
||||
context, BottomUpPageRoute(CargoTypeEditor()));
|
||||
if (cargo != null) {
|
||||
setState(() {
|
||||
cargos.add(cargo);
|
||||
});
|
||||
}
|
||||
}),
|
||||
LocalTitle(
|
||||
textKey: "shipment.box.cargo.type",
|
||||
trailing: IconButton(
|
||||
icon: Icon(
|
||||
Icons.add_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
Cargo cargo = await Navigator.push<Cargo>(
|
||||
context, BottomUpPageRoute(CargoTypeEditor()));
|
||||
_addCargo(cargo);
|
||||
}),
|
||||
),
|
||||
MyDataTable(
|
||||
headingRowHeight: 40,
|
||||
columns: [
|
||||
@@ -170,13 +173,10 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
SizedBox(
|
||||
height: 30,
|
||||
),
|
||||
TitleWithAddButton(
|
||||
titleKey: "shipment.box.dimemsion",
|
||||
),
|
||||
LocalTitle(textKey: "shipment.box.dimemsion"),
|
||||
dimBox,
|
||||
shipmentWeightBox,
|
||||
lengthBox,
|
||||
widthBox,
|
||||
heightBox,
|
||||
LocalTitle(textKey: "shipment.box.delivery"),
|
||||
DefaultDeliveryAddress(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
onTap: () async {
|
||||
@@ -199,82 +199,6 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
);
|
||||
}
|
||||
|
||||
List<TableRow> getRows(BuildContext context) {
|
||||
if (cargos == null || cargos == null) {
|
||||
return [];
|
||||
}
|
||||
int total = 0;
|
||||
var rows = cargos.map((c) {
|
||||
total += c.weight;
|
||||
return TableRow(
|
||||
children: [
|
||||
Text(
|
||||
c.type == null ? "" : c.type,
|
||||
style: textStyle,
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(c.weight == null ? "0" : c.weight.toString(),
|
||||
style: textStyle)),
|
||||
IconButton(icon: Icon(Icons.remove), onPressed: () => {})
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
|
||||
var totalRow = TableRow(
|
||||
children: [
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text("Total Weight",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
)),
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(total.toString(),
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
)),
|
||||
Container(
|
||||
width: 50,
|
||||
child:
|
||||
new Text(" ", style: TextStyle(fontWeight: FontWeight.bold))),
|
||||
],
|
||||
);
|
||||
rows.add(totalRow);
|
||||
rows.insert(
|
||||
0,
|
||||
TableRow(children: [
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: LocalText(
|
||||
context,
|
||||
"cargo.type",
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: LocalText(
|
||||
context,
|
||||
"cargo.weight",
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text("")
|
||||
]));
|
||||
return rows;
|
||||
}
|
||||
|
||||
List<MyDataRow> getCargoRows(BuildContext context) {
|
||||
if (cargos == null || cargos == null) {
|
||||
return [];
|
||||
@@ -283,7 +207,14 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
var rows = cargos.map((c) {
|
||||
total += c.weight;
|
||||
return MyDataRow(
|
||||
onSelectChanged: (bool selected) {},
|
||||
onSelectChanged: (bool selected) async {
|
||||
Cargo cargo = await Navigator.push<Cargo>(
|
||||
context,
|
||||
BottomUpPageRoute(CargoTypeEditor(
|
||||
cargo: c,
|
||||
)));
|
||||
_addCargo(cargo);
|
||||
},
|
||||
cells: [
|
||||
MyDataCell(new Text(
|
||||
c.type == null ? "" : c.type,
|
||||
@@ -300,7 +231,7 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
Icons.remove_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () => {},
|
||||
onPressed: () => {_removeCargo(c)},
|
||||
)
|
||||
],
|
||||
),
|
||||
@@ -314,7 +245,7 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
cells: [
|
||||
MyDataCell(Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text("Total Weight",
|
||||
child: Text("Total",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
)),
|
||||
@@ -333,4 +264,18 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
rows.add(totalRow);
|
||||
return rows;
|
||||
}
|
||||
|
||||
_addCargo(Cargo cargo) {
|
||||
if (cargo == null) return;
|
||||
setState(() {
|
||||
cargos.remove(cargo);
|
||||
cargos.add(cargo);
|
||||
});
|
||||
}
|
||||
|
||||
_removeCargo(Cargo cargo) {
|
||||
setState(() {
|
||||
cargos.remove(cargo);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user