update boxes

This commit is contained in:
Thinzar Win
2020-10-14 16:53:16 +06:30
parent 6c871ea066
commit 4862f1123d
11 changed files with 894 additions and 264 deletions

View File

@@ -1,3 +1,4 @@
import 'package:fcs/domain/constants.dart';
import 'package:fcs/domain/entities/box.dart';
import 'package:fcs/domain/entities/cargo.dart';
import 'package:fcs/domain/entities/package.dart';
@@ -5,7 +6,6 @@ import 'package:fcs/domain/entities/user.dart';
import 'package:fcs/domain/vo/delivery_address.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/localization/app_translations.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/language_model.dart';
@@ -18,21 +18,16 @@ 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/fcs_id_icon.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_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:fcs/pages/widgets/title_with_add_button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.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 'cargo_type_editor.dart';
import 'model/box_model.dart';
@@ -52,19 +47,22 @@ class _BoxEditorState extends State<BoxEditor> {
Box _box;
bool _isLoading = false;
bool isNew;
bool isMixBox = false;
DeliveryAddress _deliveryAddress = new DeliveryAddress();
User user;
String _selectShipmentNumber;
String _selectedCartonType;
List<Package> _packages = [];
List<Box> _shipmentBoxes = [];
List<Box> _mixBoxes = [];
List<Cargo> _cargoTypes = [];
double volumetricRatio = 0;
double shipmentWeight = 0;
Box _selectedShipmentBox;
@override
void initState() {
super.initState();
// for packages
var packageModel = Provider.of<PackageModel>(context, listen: false);
_packages = [
packageModel.packages[0],
@@ -73,6 +71,18 @@ class _BoxEditorState extends State<BoxEditor> {
_packages.forEach((p) {
p.isChecked = false;
});
//for shipment boxes
var boxModel = Provider.of<BoxModel>(context, listen: false);
_shipmentBoxes = [boxModel.boxes[0], boxModel.boxes[1], boxModel.boxes[2]];
//for mix boxes
_mixBoxes = [boxModel.boxes[0], boxModel.boxes[1], boxModel.boxes[2]];
_mixBoxes.forEach((b) {
b.isChecked = false;
});
//for shipment weight
volumetricRatio =
Provider.of<MainModel>(context, listen: false).setting.volumetricRatio;
_lengthController.addListener(_calShipmentWeight);
@@ -87,6 +97,7 @@ class _BoxEditorState extends State<BoxEditor> {
_widthController.text = _box.width.toString();
_heightController.text = _box.height.toString();
_lengthController.text = _box.length.toString();
_selectedCartonType = _box.cartonType;
isNew = false;
} else {
_cargoTypes = [
@@ -99,6 +110,7 @@ class _BoxEditorState extends State<BoxEditor> {
Provider.of<DeliveryAddressModel>(context, listen: false);
_deliveryAddress = shipmentModel.defalutAddress;
isNew = true;
_selectedCartonType = carton_from_packages;
}
}
@@ -116,46 +128,6 @@ class _BoxEditorState extends State<BoxEditor> {
super.dispose();
}
final DateFormat dateFormat = DateFormat("d MMM yyyy");
List<TimelineModel> _models() {
// 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) {
var languageModel = Provider.of<LanguageModel>(context);
@@ -174,7 +146,7 @@ class _BoxEditorState extends State<BoxEditor> {
Ionicons.ios_airplane,
color: primaryColor,
)),
items: ["A102", "A103", "A201", "A202"]
items: ["A204", "A203", "A201", "A202"]
.map((e) => DropdownMenuItem(
child: Text(
e,
@@ -189,33 +161,6 @@ class _BoxEditorState extends State<BoxEditor> {
},
));
final mixBox = Container(
child: new Row(
children: <Widget>[
new Checkbox(
value: isMixBox,
activeColor: primaryColor,
onChanged: (bool value) {
setState(() {
isMixBox = value;
});
}),
SizedBox(
width: 5,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text(
"Mix Box",
style: TextStyle(fontSize: 15.0),
),
],
),
],
),
);
final fcsIDBox = Row(
children: <Widget>[
Expanded(
@@ -251,12 +196,12 @@ class _BoxEditorState extends State<BoxEditor> {
child: Row(
children: <Widget>[
Container(
width: 40,
width: 30,
),
Expanded(
child: LocalText(context, 'box.tracking.id', color: Colors.grey),
),
LocalText(context, 'box.market', color: Colors.grey),
LocalText(context, 'box.package.desc', color: Colors.grey),
],
),
);
@@ -294,9 +239,17 @@ class _BoxEditorState extends State<BoxEditor> {
p.value.trackingID,
style: textStyle,
)),
new Text(
p.value.market == null ? "" : p.value.market,
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,
)
],
)
],
),
@@ -305,6 +258,125 @@ 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(
children: <Widget>[
Container(
width: 30,
),
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: b.value.isChecked
? Colors.grey.withOpacity(0.2)
: 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: b.key == _mixBoxes.length - 1
? Colors.white
: Colors.grey[350],
width: 1),
),
),
child: Row(
children: <Widget>[
Checkbox(
value: b.value.isChecked,
activeColor: primaryColor,
onChanged: (bool check) {
setState(() {
b.value.isChecked = check;
});
}),
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(
@@ -328,11 +400,13 @@ class _BoxEditorState extends State<BoxEditor> {
var rows = _cargoTypes.asMap().entries.map((c) {
total += c.value.weight;
return InkWell(
onTap: () {
Navigator.push(
context,
BottomUpPageRoute(CargoTypeEditor(cargo: c.value)),
);
onTap: () async {
Cargo cargo = await Navigator.push<Cargo>(
context,
BottomUpPageRoute(CargoTypeEditor(
cargo: c.value,
)));
_addCargo(cargo);
},
child: Container(
color: Colors.grey[50].withOpacity(0.2),
@@ -411,58 +485,49 @@ class _BoxEditorState extends State<BoxEditor> {
return rows;
}
final shipmentWeightBox = Container(
padding: EdgeInsets.only(left: 10),
child: DisplayText(
text: shipmentWeight != null ? shipmentWeight.toStringAsFixed(0) : "",
labelTextKey: "box.shipment_weight",
iconData: MaterialCommunityIcons.weight,
));
final lengthBox = LengthPicker(
controller: _lengthController,
lableKey: "box.length",
);
final widthBox = LengthPicker(
controller: _widthController,
lableKey: "box.width",
);
final heightBox = LengthPicker(
controller: _heightController,
lableKey: "box.height",
);
final widthBox = Container(
padding: EdgeInsets.only(left: 10, right: 10),
child: InputText(
labelTextKey: 'box.width',
iconData: FontAwesomeIcons.arrowCircleRight,
controller: _widthController));
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 heightBox = Container(
padding: EdgeInsets.only(left: 10, right: 10),
child: InputText(
labelTextKey: 'box.height',
iconData: FontAwesomeIcons.arrowAltCircleUp,
controller: _heightController));
final shipmentWeightBox = DisplayText(
text: shipmentWeight != null ? shipmentWeight.toStringAsFixed(0) : "",
labelTextKey: "box.shipment_weight",
iconData: MaterialCommunityIcons.weight,
);
final lengthBox = Container(
padding: EdgeInsets.only(left: 10, right: 10),
child: InputText(
labelTextKey: 'box.length',
iconData: FontAwesomeIcons.arrowCircleUp,
controller: _lengthController));
final createBtn = LocalButton(
textKey: "box.create.btn",
);
final createBtn = Container(
padding: EdgeInsets.only(left: 10, right: 10),
child: fcsButton(
context,
getLocalString(context, 'box.create.btn'),
callack: () {},
));
final completeBtn = LocalButton(
textKey: "box.complete.btn",
);
final completeBtn = Container(
padding: EdgeInsets.only(left: 10, right: 10),
child: fcsButton(
context,
getLocalString(context, 'box.complete.btn'),
callack: () {},
));
final deliveryBtn = Container(
padding: EdgeInsets.only(left: 10, right: 10),
child: fcsButton(
context,
getLocalString(context, 'box.deliver.btn'),
callack: () {},
));
final deliveryBtn = LocalButton(
textKey: "box.deliver.btn",
);
return LocalProgress(
inAsyncCall: _isLoading,
@@ -470,7 +535,7 @@ class _BoxEditorState extends State<BoxEditor> {
appBar: AppBar(
centerTitle: true,
leading: new IconButton(
icon: new Icon(Icons.close, color: primaryColor, size: 30),
icon: new Icon(CupertinoIcons.back, color: primaryColor, size: 30),
onPressed: () => Navigator.of(context).pop(),
),
shadowColor: Colors.transparent,
@@ -517,106 +582,85 @@ class _BoxEditorState extends State<BoxEditor> {
),
fcsIDBox,
namebox,
LocalTitle(textKey: "box.packages"),
Column(
children: [
packageTitle,
Divider(
color: Colors.grey[400],
),
Column(
children: getPackageRowList(),
),
SizedBox(height: 10),
],
),
Divider(),
Container(
padding: EdgeInsets.only(left: 10),
child: TitleWithAddButton(
iconData: MaterialCommunityIcons.briefcase_check,
titleKey: "box.cargo_type",
onTap: () async {
Cargo cargo = await Navigator.push<Cargo>(
context, BottomUpPageRoute(CargoTypeEditor()));
if (cargo != null) {
setState(() {
_box.cargoTypes.add(cargo);
});
}
}),
),
Container(
padding: EdgeInsets.only(left: 10, right: 10),
child: Column(
children: [
cargoTitle,
Divider(
color: Colors.grey[400],
),
Column(
children: getCargoRowList(),
),
SizedBox(height: 10),
],
),
),
Divider(),
SizedBox(
height: 10,
),
TitleWithAddButton(
titleKey: "box.dimension",
),
shipmentWeightBox,
widthBox,
heightBox,
lengthBox,
SizedBox(height: 25),
Divider(),
Container(
padding: EdgeInsets.only(left: 10, right: 10),
child: DefaultDeliveryAddress(
deliveryAddress: _deliveryAddress,
labelKey: "box.delivery_address",
onTap: () async {
DeliveryAddress d = await Navigator.push<DeliveryAddress>(
context,
BottomUpPageRoute(DeliveryAddressSelection(
deliveryAddress: _deliveryAddress,
)),
);
if (d == null) return;
setState(() {
this._deliveryAddress = d;
});
}),
),
SizedBox(height: 15),
Divider(),
isNew
? Container()
: Column(
_selectedCartonType == "From packages"
? Column(
children: [
Padding(
padding: EdgeInsets.only(top: 10),
child: TitleWithAddButton(
titleKey: "box.status",
),
LocalTitle(textKey: "box.packages"),
packageTitle,
Divider(
color: Colors.grey[400],
),
Container(
height: 230,
padding: EdgeInsets.only(left: 10),
child: isNew
? Container()
: Timeline(
children: _models(),
position: TimelinePosition.Left),
Column(
children: getPackageRowList(),
),
],
)
: _selectedCartonType == "From shipments"
? Column(
children: [
LocalTitle(textKey: "box.shipment.boxes"),
shipmentBoxTitle,
Divider(
color: Colors.grey[400],
),
Column(
children: getshipmentBoxRowList(),
),
],
)
: _selectedCartonType == "Mix carton"
? Column(
children: [
LocalTitle(textKey: "box.shipment.boxes"),
mixBoxTitle,
Divider(
color: Colors.grey[400],
),
Column(
children: getMixBoxRowList(),
)
],
)
: Container(),
LocalTitle(
textKey: "box.cargo_type",
trailing: IconButton(
icon: Icon(
Icons.add_circle,
color: primaryColor,
),
isNew ? Container() : Divider(),
onPressed: () async {
Cargo cargo = await Navigator.push<Cargo>(
context, BottomUpPageRoute(CargoTypeEditor()));
_addCargo(cargo);
}),
),
cargoTitle,
Divider(
color: Colors.grey[400],
),
Column(
children: getCargoRowList(),
),
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,
BottomUpPageRoute(DeliveryAddressSelection(
deliveryAddress: _deliveryAddress,
)),
);
if (d == null) return;
setState(() {
this._deliveryAddress = d;
});
}),
SizedBox(
height: 10,
),
@@ -650,4 +694,12 @@ class _BoxEditorState extends State<BoxEditor> {
);
}).toList();
}
_addCargo(Cargo cargo) {
if (cargo == null) return;
setState(() {
_cargoTypes.remove(cargo);
_cargoTypes.add(cargo);
});
}
}