add shipments
This commit is contained in:
@@ -66,6 +66,7 @@ class _CargoTypeEditorState extends State<CargoTypeEditor> {
|
||||
_cargo = v;
|
||||
});
|
||||
},
|
||||
labelKey: "cargo.type",
|
||||
iconData: Icons.text_format,
|
||||
selectedValue: _cargo,
|
||||
values: cargos,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/domain/entities/fcs_shipment.dart';
|
||||
import 'package:fcs/domain/entities/package.dart';
|
||||
import 'package:fcs/domain/entities/user.dart';
|
||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||
@@ -8,6 +9,7 @@ import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/localization/app_translations.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/fcs_shipment/model/fcs_shipment_model.dart';
|
||||
import 'package:fcs/pages/main/model/language_model.dart';
|
||||
import 'package:fcs/pages/main/model/main_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
@@ -21,9 +23,11 @@ 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_dropdown.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/my_data_table.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -32,54 +36,38 @@ import 'package:provider/provider.dart';
|
||||
import 'cargo_type_editor.dart';
|
||||
import 'model/carton_model.dart';
|
||||
|
||||
class BoxEditor extends StatefulWidget {
|
||||
class CartonEditor extends StatefulWidget {
|
||||
final Carton box;
|
||||
BoxEditor({this.box});
|
||||
CartonEditor({this.box});
|
||||
|
||||
@override
|
||||
_BoxEditorState createState() => _BoxEditorState();
|
||||
_CartonEditorState createState() => _CartonEditorState();
|
||||
}
|
||||
|
||||
class _BoxEditorState extends State<BoxEditor> {
|
||||
class _CartonEditorState extends State<CartonEditor> {
|
||||
TextEditingController _widthController = new TextEditingController();
|
||||
TextEditingController _heightController = new TextEditingController();
|
||||
TextEditingController _lengthController = new TextEditingController();
|
||||
|
||||
Carton _box;
|
||||
bool _isLoading = false;
|
||||
bool isNew;
|
||||
bool _isNew;
|
||||
DeliveryAddress _deliveryAddress = new DeliveryAddress();
|
||||
User user;
|
||||
String _selectShipmentNumber;
|
||||
User _user;
|
||||
String _selectedCartonType;
|
||||
List<Package> _packages = [];
|
||||
List<Carton> _shipmentBoxes = [];
|
||||
List<Carton> _mixBoxes = [];
|
||||
List<CargoType> _cargoTypes = [];
|
||||
double volumetricRatio = 0;
|
||||
double shipmentWeight = 0;
|
||||
Carton _selectedShipmentBox;
|
||||
FcsShipment _fcsShipment;
|
||||
List<FcsShipment> _fcsShipments;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 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);
|
||||
_shipmentBoxes = [
|
||||
boxModel.boxeList[0],
|
||||
boxModel.boxeList[1],
|
||||
boxModel.boxeList[2]
|
||||
];
|
||||
|
||||
//for mix boxes
|
||||
_mixBoxes = [
|
||||
@@ -102,29 +90,72 @@ class _BoxEditorState extends State<BoxEditor> {
|
||||
if (widget.box != null) {
|
||||
_box = widget.box;
|
||||
_deliveryAddress = _box.deliveryAddress;
|
||||
_cargoTypes = _box.cargoTypes;
|
||||
_selectShipmentNumber = _box.shipmentNumber;
|
||||
_widthController.text = _box.width.toString();
|
||||
_heightController.text = _box.height.toString();
|
||||
_lengthController.text = _box.length.toString();
|
||||
_selectedCartonType = _box.cartonType;
|
||||
isNew = false;
|
||||
user = User(fcsID: _box.fcsID, name: _box.userName);
|
||||
_isNew = false;
|
||||
_user = User(fcsID: _box.fcsID, name: _box.userName);
|
||||
} else {
|
||||
_cargoTypes = [
|
||||
CargoType(id: "1", name: 'General', weight: 25),
|
||||
CargoType(id: "2", name: 'Medicine', weight: 20),
|
||||
CargoType(id: "3", name: 'Dangerous', weight: 30)
|
||||
];
|
||||
|
||||
var shipmentModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
_deliveryAddress = shipmentModel.defalutAddress;
|
||||
isNew = true;
|
||||
_box = Carton(cargoTypes: []);
|
||||
_lengthController.text = "12";
|
||||
_widthController.text = "12";
|
||||
_heightController.text = "12";
|
||||
_isNew = true;
|
||||
_selectedCartonType = carton_from_packages;
|
||||
_loadFcsShipments();
|
||||
}
|
||||
}
|
||||
|
||||
_loadFcsShipments() async {
|
||||
FcsShipmentModel fcsShipmentModel =
|
||||
Provider.of<FcsShipmentModel>(context, listen: false);
|
||||
var fcsShipments = await fcsShipmentModel.getActiveFcsShipments();
|
||||
var fcsShipment = fcsShipments.firstWhere((e) => e.id == _box.fcsShipmentID,
|
||||
orElse: () => null);
|
||||
setState(() {
|
||||
_fcsShipments = fcsShipments;
|
||||
_fcsShipment = fcsShipment;
|
||||
});
|
||||
}
|
||||
|
||||
_loadPackages() async {
|
||||
if (_user == null) return;
|
||||
PackageModel packageModel =
|
||||
Provider.of<PackageModel>(context, listen: false);
|
||||
List<Package> packages = await packageModel.getPackages(_user.id);
|
||||
String prevCompare;
|
||||
packages.forEach((p) {
|
||||
String compare = (p.deliveryAddress?.fullName ?? "") +
|
||||
(p.deliveryAddress?.phoneNumber ?? "");
|
||||
if (prevCompare != null && compare == prevCompare) {
|
||||
p.isChecked = true;
|
||||
} else {
|
||||
p.isChecked = false;
|
||||
}
|
||||
if (prevCompare == null) {
|
||||
p.isChecked = true;
|
||||
prevCompare = compare;
|
||||
}
|
||||
});
|
||||
|
||||
setState(() {
|
||||
_packages = packages;
|
||||
});
|
||||
_populateDeliveryAddress();
|
||||
}
|
||||
|
||||
_populateDeliveryAddress() {
|
||||
if (_packages == null) return;
|
||||
var d = _packages
|
||||
.firstWhere((p) => p.isChecked && p.deliveryAddress != null,
|
||||
orElse: () => null)
|
||||
?.deliveryAddress;
|
||||
setState(() {
|
||||
_deliveryAddress = d;
|
||||
});
|
||||
}
|
||||
|
||||
_calShipmentWeight() {
|
||||
double l = double.parse(_lengthController.text, (s) => 0);
|
||||
double w = double.parse(_widthController.text, (s) => 0);
|
||||
@@ -141,42 +172,26 @@ class _BoxEditorState extends State<BoxEditor> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var languageModel = Provider.of<LanguageModel>(context);
|
||||
var boxModel = Provider.of<CartonModel>(context);
|
||||
|
||||
var shipmentBox = Container(
|
||||
child: DropdownButtonFormField(
|
||||
value: _selectShipmentNumber,
|
||||
decoration: InputDecoration(
|
||||
fillColor: Colors.white,
|
||||
labelText: AppTranslations.of(context).text("box.fcs_shipment_num"),
|
||||
labelStyle: languageModel.isEng
|
||||
? TextStyle(fontWeight: FontWeight.w500)
|
||||
: TextStyle(fontWeight: FontWeight.w500, fontFamily: "Myanmar3"),
|
||||
icon: Icon(
|
||||
Ionicons.ios_airplane,
|
||||
color: primaryColor,
|
||||
)),
|
||||
items: ["A204", "A203", "A201", "A202"]
|
||||
.map((e) => DropdownMenuItem(
|
||||
child: Text(
|
||||
e,
|
||||
style: TextStyle(color: primaryColor),
|
||||
),
|
||||
value: e))
|
||||
.toList(),
|
||||
onChanged: (value) {
|
||||
var fcsShipmentsBox = LocalDropdown<FcsShipment>(
|
||||
callback: (v) {
|
||||
setState(() {
|
||||
_selectShipmentNumber = value;
|
||||
_fcsShipment = v;
|
||||
});
|
||||
},
|
||||
));
|
||||
labelKey: "shipment.pack.fcs.shipment",
|
||||
iconData: MaterialCommunityIcons.worker,
|
||||
display: (u) => u.shipmentNumber,
|
||||
selectedValue: _fcsShipment,
|
||||
values: _fcsShipments,
|
||||
);
|
||||
|
||||
final fcsIDBox = Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: DisplayText(
|
||||
text: user != null ? user.fcsID : "",
|
||||
text: _user?.fcsID ?? "",
|
||||
labelTextKey: "box.fcs.id",
|
||||
icon: FcsIDIcon(),
|
||||
)),
|
||||
@@ -184,20 +199,15 @@ class _BoxEditorState extends State<BoxEditor> {
|
||||
icon: Icon(Icons.search, color: primaryColor),
|
||||
onPressed: () => searchUser(context, callbackUserSelect: (u) {
|
||||
setState(() {
|
||||
this.user = u;
|
||||
this._user = u;
|
||||
_loadPackages();
|
||||
});
|
||||
})),
|
||||
],
|
||||
);
|
||||
|
||||
final phoneNumberBox = DisplayText(
|
||||
text: user != null ? user.phoneNumber : "",
|
||||
labelTextKey: "box.phone",
|
||||
iconData: Icons.phone,
|
||||
);
|
||||
|
||||
final namebox = DisplayText(
|
||||
text: user != null ? user.name : "",
|
||||
text: _user?.name ?? "",
|
||||
labelTextKey: "box.name",
|
||||
iconData: Icons.person,
|
||||
);
|
||||
@@ -241,23 +251,42 @@ class _BoxEditorState extends State<BoxEditor> {
|
||||
value: p.value.isChecked,
|
||||
activeColor: primaryColor,
|
||||
onChanged: (bool check) {
|
||||
if (check &&
|
||||
_deliveryAddress != null &&
|
||||
p.value.deliveryAddress?.id != _deliveryAddress.id) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
p.value.isChecked = check;
|
||||
});
|
||||
_populateDeliveryAddress();
|
||||
}),
|
||||
Expanded(
|
||||
child: new Text(
|
||||
p.value.trackingID,
|
||||
style: textStyle,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
p.value.trackingID,
|
||||
style: textStyle,
|
||||
),
|
||||
Text(
|
||||
p.value.deliveryAddress?.fullName ?? "",
|
||||
style: textStyle,
|
||||
),
|
||||
Text(
|
||||
p.value.deliveryAddress?.phoneNumber ?? "",
|
||||
style: textStyle,
|
||||
),
|
||||
],
|
||||
)),
|
||||
new Column(
|
||||
children: [
|
||||
new Text(
|
||||
p.value.desc == null ? "" : p.value.desc,
|
||||
p.value?.desc ?? "",
|
||||
style: textStyle,
|
||||
),
|
||||
new Text(
|
||||
"(${p.value.market == null ? "" : p.value.market})",
|
||||
"(${p.value?.market ?? ""})",
|
||||
style: textStyle,
|
||||
)
|
||||
],
|
||||
@@ -269,66 +298,6 @@ class _BoxEditorState extends State<BoxEditor> {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
final shipmentBoxTitle = Container(
|
||||
padding: EdgeInsets.only(right: 10.0, top: 20),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
width: 30,
|
||||
),
|
||||
Expanded(
|
||||
child:
|
||||
LocalText(context, 'box.shipment_number', color: Colors.grey),
|
||||
),
|
||||
LocalText(context, 'box.shipment.desc', color: Colors.grey),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
List<Widget> getshipmentBoxRowList() {
|
||||
return _shipmentBoxes.asMap().entries.map((s) {
|
||||
return Container(
|
||||
color: Colors.grey[50].withOpacity(0.2),
|
||||
child: Container(
|
||||
padding:
|
||||
EdgeInsets.only(left: 0.0, right: 10.0, top: 3.0, bottom: 3.0),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: s.key == _shipmentBoxes.length - 1
|
||||
? Colors.white
|
||||
: Colors.grey[350],
|
||||
width: 1),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Radio(
|
||||
activeColor: primaryColor,
|
||||
groupValue: _selectedShipmentBox,
|
||||
value: s.value,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_selectedShipmentBox = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: new Text(
|
||||
s.value.shipmentNumber,
|
||||
style: textStyle,
|
||||
)),
|
||||
new Text(
|
||||
s.value.desc == null ? "" : s.value.desc,
|
||||
style: textStyle,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
final mixBoxTitle = Container(
|
||||
padding: EdgeInsets.only(right: 10.0, top: 20),
|
||||
child: Row(
|
||||
@@ -388,113 +357,6 @@ class _BoxEditorState extends State<BoxEditor> {
|
||||
}).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: 20),
|
||||
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: () async {
|
||||
CargoType cargo = await Navigator.push<CargoType>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => CargoTypeEditor(cargo: c.value)),
|
||||
);
|
||||
_addCargo(cargo);
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.grey[50].withOpacity(0.2),
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(
|
||||
left: 15.0, right: 0.0, top: 0.0, bottom: 0.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,
|
||||
)),
|
||||
Row(
|
||||
children: [
|
||||
new Text(
|
||||
c.value.weight == null
|
||||
? "0"
|
||||
: c.value.weight.toString(),
|
||||
style: textStyle,
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.remove_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_cargoTypes.remove(c.value);
|
||||
});
|
||||
},
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).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: LocalText(context, "box.cargo.total",
|
||||
color: Colors.black87, fontWeight: FontWeight.bold),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 40.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",
|
||||
@@ -538,6 +400,15 @@ class _BoxEditorState extends State<BoxEditor> {
|
||||
final deliveryBtn = LocalButton(
|
||||
textKey: "box.deliver.btn",
|
||||
);
|
||||
final cartonTypeBox = LocalRadioButtons(
|
||||
values: boxModel.cartonTypes,
|
||||
selectedValue: _selectedCartonType,
|
||||
callback: (v) {
|
||||
print(v);
|
||||
setState(() {
|
||||
_selectedCartonType = v;
|
||||
});
|
||||
});
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
@@ -565,34 +436,20 @@ class _BoxEditorState extends State<BoxEditor> {
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
widget.box == null
|
||||
? Container()
|
||||
: Center(child: nameWidget(_box.packageNumber)),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
LocalTitle(textKey: "box.type.title"),
|
||||
LocalRadioButtons(
|
||||
values: boxModel.cartonTypes,
|
||||
selectedValue: _selectedCartonType,
|
||||
callback: (v) {
|
||||
print(v);
|
||||
setState(() {
|
||||
_selectedCartonType = v;
|
||||
});
|
||||
}),
|
||||
cartonTypeBox,
|
||||
LocalTitle(textKey: "box.shipment_info"),
|
||||
shipmentBox,
|
||||
fcsShipmentsBox,
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
fcsIDBox,
|
||||
namebox,
|
||||
_selectedCartonType == "From packages"
|
||||
_selectedCartonType == carton_from_packages
|
||||
? Column(
|
||||
children: [
|
||||
LocalTitle(textKey: "box.packages"),
|
||||
@@ -605,35 +462,22 @@ class _BoxEditorState extends State<BoxEditor> {
|
||||
),
|
||||
],
|
||||
)
|
||||
: _selectedCartonType == "From shipments"
|
||||
: _selectedCartonType == carton_mix_box
|
||||
? Column(
|
||||
children: [
|
||||
LocalTitle(textKey: "box.shipment.boxes"),
|
||||
shipmentBoxTitle,
|
||||
mixBoxTitle,
|
||||
Divider(
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
Column(
|
||||
children: getshipmentBoxRowList(),
|
||||
),
|
||||
children: getMixBoxRowList(),
|
||||
)
|
||||
],
|
||||
)
|
||||
: _selectedCartonType == "Mix carton"
|
||||
? Column(
|
||||
children: [
|
||||
LocalTitle(textKey: "box.shipment.boxes"),
|
||||
mixBoxTitle,
|
||||
Divider(
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
Column(
|
||||
children: getMixBoxRowList(),
|
||||
)
|
||||
],
|
||||
)
|
||||
: Container(),
|
||||
: Container(),
|
||||
LocalTitle(
|
||||
textKey: "box.cargo_type",
|
||||
textKey: "box.cargo.type",
|
||||
trailing: IconButton(
|
||||
icon: Icon(
|
||||
Icons.add_circle,
|
||||
@@ -641,43 +485,39 @@ class _BoxEditorState extends State<BoxEditor> {
|
||||
),
|
||||
onPressed: () async {
|
||||
CargoType cargo = await Navigator.push<CargoType>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => CargoTypeEditor()),
|
||||
);
|
||||
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => CargoTypeEditor()));
|
||||
_addCargo(cargo);
|
||||
}),
|
||||
),
|
||||
cargoTitle,
|
||||
Divider(
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
Column(
|
||||
children: getCargoRowList(),
|
||||
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),
|
||||
),
|
||||
LocalTitle(textKey: "box.dimension"),
|
||||
dimBox,
|
||||
shipmentWeightBox,
|
||||
LocalTitle(textKey: "box.delivery_address"),
|
||||
DefaultDeliveryAddress(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
labelKey: "box.delivery_address",
|
||||
onTap: () async {
|
||||
DeliveryAddress d = await Navigator.push<DeliveryAddress>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
)),
|
||||
);
|
||||
if (d == null) return;
|
||||
setState(() {
|
||||
this._deliveryAddress = d;
|
||||
});
|
||||
}),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
deliveryAddress: _deliveryAddress,
|
||||
labelKey: "box.delivery_address",
|
||||
),
|
||||
widget.box == null
|
||||
? createBtn
|
||||
@@ -700,6 +540,75 @@ class _BoxEditorState extends State<BoxEditor> {
|
||||
);
|
||||
}
|
||||
|
||||
List<MyDataRow> getCargoRows(BuildContext context) {
|
||||
if (_box?.cargoTypes == null) {
|
||||
return [];
|
||||
}
|
||||
double total = 0;
|
||||
var rows = _box.cargoTypes.map((c) {
|
||||
total += c.weight;
|
||||
return MyDataRow(
|
||||
onSelectChanged: (bool selected) async {
|
||||
CargoType cargo = await Navigator.push<CargoType>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => CargoTypeEditor(
|
||||
cargo: c,
|
||||
)));
|
||||
_addCargo(cargo);
|
||||
},
|
||||
cells: [
|
||||
MyDataCell(new Text(
|
||||
c.name == null ? "" : c.name,
|
||||
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,
|
||||
),
|
||||
onPressed: () => {_removeCargo(c)},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
|
||||
var totalRow = MyDataRow(
|
||||
onSelectChanged: (bool selected) {},
|
||||
cells: [
|
||||
MyDataCell(Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: LocalText(
|
||||
context,
|
||||
"shipment.cargo.total",
|
||||
color: Colors.black87,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
)),
|
||||
MyDataCell(
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 48.0),
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(total.toString(),
|
||||
style: TextStyle(fontWeight: FontWeight.bold))),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
rows.add(totalRow);
|
||||
return rows;
|
||||
}
|
||||
|
||||
List<Widget> getAddressList(
|
||||
BuildContext context, List<DeliveryAddress> addresses) {
|
||||
return addresses.asMap().entries.map((s) {
|
||||
@@ -713,8 +622,49 @@ class _BoxEditorState extends State<BoxEditor> {
|
||||
_addCargo(CargoType cargo) {
|
||||
if (cargo == null) return;
|
||||
setState(() {
|
||||
_cargoTypes.remove(cargo);
|
||||
_cargoTypes.add(cargo);
|
||||
_box.cargoTypes.remove(cargo);
|
||||
_box.cargoTypes.add(cargo);
|
||||
});
|
||||
}
|
||||
|
||||
_removeCargo(CargoType cargo) {
|
||||
setState(() {
|
||||
_box.cargoTypes.remove(cargo);
|
||||
});
|
||||
}
|
||||
|
||||
_save() async {
|
||||
_box.cartonType = _selectedCartonType;
|
||||
_box.fcsShipmentID = _fcsShipment.id;
|
||||
_box.userID = _user.id;
|
||||
_box.packages = _packages.map((e) => e.isChecked ? e : null).toList();
|
||||
|
||||
double l = double.parse(_lengthController.text, (s) => 0);
|
||||
double w = double.parse(_widthController.text, (s) => 0);
|
||||
double h = double.parse(_heightController.text, (s) => 0);
|
||||
_box.length = l;
|
||||
_box.width = w;
|
||||
_box.height = h;
|
||||
_box.deliveryAddress = _deliveryAddress;
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
CartonModel cartonModel =
|
||||
Provider.of<CartonModel>(context, listen: false);
|
||||
if (_isNew) {
|
||||
await cartonModel.createCarton(_box);
|
||||
} else {
|
||||
await cartonModel.updateCarton(_box);
|
||||
}
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,20 +21,20 @@ import 'package:provider/provider.dart';
|
||||
import 'package:timeline_list/timeline.dart';
|
||||
import 'package:timeline_list/timeline_model.dart';
|
||||
|
||||
import 'box_editor.dart';
|
||||
import 'carton_editor.dart';
|
||||
import 'model/carton_model.dart';
|
||||
|
||||
final DateFormat dateFormat = DateFormat("d MMM yyyy");
|
||||
|
||||
class BoxInfo extends StatefulWidget {
|
||||
class CartonInfo extends StatefulWidget {
|
||||
final Carton box;
|
||||
BoxInfo({this.box});
|
||||
CartonInfo({this.box});
|
||||
|
||||
@override
|
||||
_BoxInfoState createState() => _BoxInfoState();
|
||||
_CartonInfoState createState() => _CartonInfoState();
|
||||
}
|
||||
|
||||
class _BoxInfoState extends State<BoxInfo> {
|
||||
class _CartonInfoState extends State<CartonInfo> {
|
||||
bool _isLoading = false;
|
||||
Carton _box;
|
||||
String _selectedCartonType;
|
||||
@@ -162,7 +162,7 @@ class _BoxInfoState extends State<BoxInfo> {
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text(_selectedCartonType),
|
||||
Text(_selectedCartonType ?? ""),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -469,7 +469,7 @@ class _BoxInfoState extends State<BoxInfo> {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: ListView(children: <Widget>[
|
||||
Center(child: nameWidget(_box.packageNumber)),
|
||||
// Center(child: nameWidget(_box.packageNumber)),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
@@ -554,7 +554,7 @@ class _BoxInfoState extends State<BoxInfo> {
|
||||
_gotoEditor() async {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => BoxEditor(box: widget.box)),
|
||||
CupertinoPageRoute(builder: (context) => CartonEditor(box: widget.box)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,15 +8,15 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'box_editor.dart';
|
||||
import 'box_list_row.dart';
|
||||
import 'carton_editor.dart';
|
||||
import 'carton_list_row.dart';
|
||||
|
||||
class BoxList extends StatefulWidget {
|
||||
class CartonList extends StatefulWidget {
|
||||
@override
|
||||
_BoxListState createState() => _BoxListState();
|
||||
_CartonListState createState() => _CartonListState();
|
||||
}
|
||||
|
||||
class _BoxListState extends State<BoxList> {
|
||||
class _CartonListState extends State<CartonList> {
|
||||
bool _isLoading = false;
|
||||
var _controller = ScrollController();
|
||||
|
||||
@@ -97,13 +97,15 @@ class _BoxListState extends State<BoxList> {
|
||||
controller: _controller,
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
color: Colors.black,
|
||||
height: 1,
|
||||
),
|
||||
scrollDirection: Axis.vertical,
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
shrinkWrap: true,
|
||||
itemCount: boxModel.boxes.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return BoxListRow(box: boxModel.boxes[index]);
|
||||
return CartonListRow(
|
||||
key: ValueKey(boxModel.boxes[index].id),
|
||||
box: boxModel.boxes[index]);
|
||||
}),
|
||||
onRefresh: () => boxModel.refresh(),
|
||||
),
|
||||
@@ -131,7 +133,7 @@ class _BoxListState extends State<BoxList> {
|
||||
_newBox() {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => BoxEditor()),
|
||||
CupertinoPageRoute(builder: (context) => CartonEditor()),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,21 @@
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'box_info.dart';
|
||||
import 'carton_info.dart';
|
||||
|
||||
class BoxListRow extends StatefulWidget {
|
||||
class CartonListRow extends StatefulWidget {
|
||||
final Carton box;
|
||||
const BoxListRow({this.box});
|
||||
const CartonListRow({Key key, this.box}) : super(key: key);
|
||||
|
||||
@override
|
||||
_BoxListRowState createState() => _BoxListRowState();
|
||||
_CartonListRowState createState() => _CartonListRowState();
|
||||
}
|
||||
|
||||
class _BoxListRowState extends State<BoxListRow> {
|
||||
class _CartonListRowState extends State<CartonListRow> {
|
||||
final double dotSize = 15.0;
|
||||
Carton _box = new Carton();
|
||||
final DateFormat dateFormat = new DateFormat("dd MMM yyyy");
|
||||
@@ -26,15 +28,15 @@ class _BoxListRowState extends State<BoxListRow> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 15, right: 15),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => BoxInfo(box: _box)),
|
||||
);
|
||||
},
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => CartonInfo(box: _box)),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(left: 15, right: 15),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
@@ -42,6 +44,14 @@ class _BoxListRowState extends State<BoxListRow> {
|
||||
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||
child: new Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 5, right: 10),
|
||||
child: Icon(
|
||||
MaterialCommunityIcons.package,
|
||||
color: primaryColor,
|
||||
size: 30,
|
||||
),
|
||||
),
|
||||
new Expanded(
|
||||
child: new Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -49,9 +59,7 @@ class _BoxListRowState extends State<BoxListRow> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
_box.packageNumber == null
|
||||
? ''
|
||||
: _box.packageNumber,
|
||||
_box.cartonNumber ?? "",
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.black),
|
||||
),
|
||||
@@ -59,7 +67,7 @@ class _BoxListRowState extends State<BoxListRow> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 10.0, top: 10),
|
||||
child: new Text(
|
||||
dateFormat.format(_box.arrivedDate),
|
||||
_box.userName ?? "",
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.grey),
|
||||
),
|
||||
@@ -82,14 +90,7 @@ class _BoxListRowState extends State<BoxListRow> {
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
new Text(
|
||||
_box.weight == null
|
||||
? ''
|
||||
: _box.weight.toString() + 'lb - ',
|
||||
style:
|
||||
new TextStyle(fontSize: 15.0, color: Colors.grey),
|
||||
),
|
||||
new Text(
|
||||
_box.price == null ? "" : "\$ " + _box.price.toString(),
|
||||
"${_box.actualWeight?.toString() ?? ''} lb",
|
||||
style:
|
||||
new TextStyle(fontSize: 15.0, color: Colors.grey),
|
||||
),
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/data/services/services.dart';
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
@@ -312,11 +313,7 @@ class CartonModel extends BaseModel {
|
||||
});
|
||||
}
|
||||
|
||||
List<String> cartonTypes = [
|
||||
carton_from_packages,
|
||||
carton_from_shipments,
|
||||
carton_mix_box
|
||||
];
|
||||
List<String> cartonTypes = [carton_from_packages, carton_mix_box];
|
||||
|
||||
set selectedIndex(int index) {
|
||||
_selectedIndex = index;
|
||||
@@ -430,4 +427,12 @@ class CartonModel extends BaseModel {
|
||||
.map((e) => Carton.fromMap(e.data, e.documentID))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<void> createCarton(Carton carton) {
|
||||
return Services.instance.cartonService.createCarton(carton);
|
||||
}
|
||||
|
||||
Future<void> updateCarton(Carton carton) {
|
||||
return Services.instance.cartonService.updateCarton(carton);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user