add prompt confirmation and update carton

This commit is contained in:
Thinzar Win
2020-12-08 20:24:15 +06:30
parent 1a7b1ce97b
commit 20477b6915
39 changed files with 637 additions and 259 deletions

View File

@@ -1,6 +1,8 @@
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/custom_duty.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/rates/custom_list.dart';
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/local_title.dart';
@@ -8,7 +10,6 @@ import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'input_text_border.dart';
class CargoTypeAddition extends StatefulWidget {
@@ -24,10 +25,12 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
@override
void initState() {
super.initState();
cargos =
Provider.of<ShipmentRateModel>(context, listen: false).rate.cargoTypes;
var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
cargos = List.from(shipmentRateModel.rate.cargoTypes);
cargos.forEach((p) {
p.isChecked = false;
p.isCutomDuty = false;
p.weight = 0;
p.qty = null;
});
@@ -55,7 +58,7 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
),
),
SizedBox(
width: 50,
width: 40,
),
LocalText(
context,
@@ -95,40 +98,58 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
}),
Expanded(child: new Text(c.name, style: textStyle)),
SizedBox(
width: 50,
width: c.isCutomDuty ? 50 : 40,
child: c.isCutomDuty
? InkWell(
onTap: () {
setState(() {
cargos.removeWhere((t) => t.name == c.name);
});
},
child: Icon(
Icons.remove_circle,
color: Colors.black45,
),
)
: Container(),
),
Container(
height: 30,
width: 40,
child: InputTextBorder(
onAdd: (value) {
setState(() {
if (value == "" || value == null) {
c.isChecked = false;
} else {
c.qty = int.parse(value);
c.isChecked = true;
}
});
},
),
width: 50,
child: c.isCutomDuty
? InputTextBorder(
onAdd: (value) {
setState(() {
if (value == "" || value == null) {
c.isChecked = false;
} else {
c.qty = int.parse(value);
c.isChecked = true;
}
});
},
)
: Center(child: Text("-")),
),
Spacer(),
Container(
height: 30,
width: 60,
child: InputTextBorder(
onAdd: (value) {
setState(() {
if (value == "" || value == null) {
c.isChecked = false;
} else {
c.weight = double.parse(value);
c.isChecked = true;
}
});
},
),
child: Center(
child: Text(
c.weight == null ? "" : c.weight.toStringAsFixed(2))),
// child: InputTextBorder(
// onAdd: (value) {
// setState(() {
// if (value == "" || value == null) {
// c.isChecked = false;
// } else {
// c.weight = double.parse(value);
// c.isChecked = true;
// }
// });
// },
// ),
),
],
),
@@ -146,6 +167,7 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
Navigator.pop(context, _cargos);
},
);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
@@ -169,7 +191,21 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
child: ListView(
shrinkWrap: true,
children: <Widget>[
LocalTitle(textKey: "box.select.cargo.title"),
LocalTitle(
textKey: "box.select.cargo.title",
trailing: IconButton(
icon: Icon(
Icons.add_circle,
color: primaryColor,
),
onPressed: () async {
CustomDuty customDuty = await Navigator.of(context).push(
CupertinoPageRoute(
builder: (context) =>
CustomList(selected: true)));
_addCustom(customDuty);
}),
),
cargoTableTitleBox,
Divider(
color: Colors.grey[400],
@@ -186,4 +222,14 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
),
);
}
_addCustom(CustomDuty customDuty) {
if (customDuty == null) return;
if (cargos.any((c) => c.name == customDuty.productType)) return;
setState(() {
cargos.add(CargoType(name: customDuty.productType, isCutomDuty: true));
});
}
}

View File

@@ -28,8 +28,13 @@ class _CargoTableState extends State<CargoTable> {
double totalWeight = 0;
List<CargoType> _cargos = [];
double remainingWeight = 0;
@override
Widget build(BuildContext context) {
remainingWeight =
widget.cargoTypes.length == 0 ? this.totalWeight : remainingWeight;
this._cargos = widget.cargoTypes.length == 0 ? [] : this._cargos;
return MyDataTable(
headingRowHeight: 40,
columns: [
@@ -41,17 +46,10 @@ class _CargoTableState extends State<CargoTable> {
),
),
MyDataColumn(
label: Row(
children: [
Container(
padding: EdgeInsets.only(left:50),
child: LocalText(
context,
"cargo.weight",
color: Colors.grey,
),
),
],
label: LocalText(
context,
"cargo.weight",
color: Colors.grey,
),
),
],
@@ -65,12 +63,48 @@ class _CargoTableState extends State<CargoTable> {
}
List<String> _list = [];
List<String> _types = [];
double _total = 0;
var rows = widget.cargoTypes.map((c) {
_total += c.weight;
return MyDataRow(
onSelectChanged: (bool selected) async {},
onSelectChanged: (bool selected) async {
if (this.totalWeight <= 0) {
showMsgDialog(context, "Error", "Please insert total weight");
return;
}
if (c.isCutomDuty) return;
CargoType cargo = await Navigator.push<CargoType>(
context,
CupertinoPageRoute(
builder: (context) => CargoTypeEditor(
cargo: c,
)));
if (widget.onAdd != null) widget.onAdd(cargo);
if (cargo == null) return;
this._cargos.add(cargo);
if (this.remainingWeight <= 0) return;
this.remainingWeight -= cargo.weight;
this._cargos.forEach((c) {
_list.add(c.name);
});
widget.cargoTypes.forEach((c) {
_types.add(c.name);
});
if (this._cargos.length == widget.cargoTypes.length - 1) {
_types.forEach((t) {
if (!_list.contains(t)) {
widget.cargoTypes.forEach((c) {
if (c.name == t) {
c.weight = this.remainingWeight;
}
});
}
});
}
},
cells: [
MyDataCell(Row(
children: [
@@ -88,7 +122,8 @@ class _CargoTableState extends State<CargoTable> {
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(c.weight.toStringAsFixed(2), style: textStyle),
Text(c.weight == null ? "0.00" : c.weight.toStringAsFixed(2),
style: textStyle),
widget.onRemove == null
? SizedBox(
width: 50,
@@ -134,35 +169,13 @@ class _CargoTableState extends State<CargoTable> {
if (_t == null) return;
setState(() {
totalWeight = _t;
this.remainingWeight = this.totalWeight - _total;
widget.cargoTypes.forEach((c) {
if (c.qty == null) {
this._cargos.add(c);
}
});
this._cargos.forEach((c) {
_list.add(c.name);
});
widget.cargoTypes.forEach((c) {
_types.add(c.name);
});
if (this._cargos.length == widget.cargoTypes.length - 1) {
_types.forEach((t) {
if (!_list.contains(t)) {
widget.cargoTypes.forEach((c) {
if (c.name == t) {
c.weight = this.remainingWeight;
}
});
}
});
}
remainingWeight = totalWeight;
});
},
child: Container(
padding: const EdgeInsets.all(7.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
border: Border.all(color: primaryColor),
borderRadius: BorderRadius.all(Radius.circular(5.0)),
),
child: Text(totalWeight.toStringAsFixed(2),
@@ -181,4 +194,78 @@ class _CargoTableState extends State<CargoTable> {
double _r = this.totalWeight < total ? 0 : this.totalWeight - total;
return _r;
}
List<MyDataRow> _getCargoRows(BuildContext context) {
if (widget.cargoTypes == null) {
return [];
}
double total = 0;
var rows = widget.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,
)));
if (widget.onAdd != null) widget.onAdd(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.toStringAsFixed(2),
style: textStyle),
widget.onRemove == null
? SizedBox(
width: 50,
)
: IconButton(
icon: Icon(
Icons.remove_circle,
color: primaryColor,
),
onPressed: () {
if (widget.onRemove != null) widget.onRemove(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.toStringAsFixed(2),
style: TextStyle(fontWeight: FontWeight.bold))),
),
),
],
);
rows.add(totalRow);
return rows;
}
}

View File

@@ -41,10 +41,17 @@ class _CargoTableState extends State<CargoTable> {
),
),
MyDataColumn(
label: LocalText(
context,
"cargo.weight",
color: Colors.grey,
label: Row(
children: [
Container(
padding: EdgeInsets.only(left: 50),
child: LocalText(
context,
"cargo.weight",
color: Colors.grey,
),
),
],
),
),
],
@@ -58,50 +65,24 @@ class _CargoTableState extends State<CargoTable> {
}
List<String> _list = [];
List<String> _types = [];
double _total = 0;
var rows = widget.cargoTypes.map((c) {
_total += c.weight;
return MyDataRow(
onSelectChanged: (bool selected) async {
if (this.totalWeight <= 0) {
showMsgDialog(context, "Error", "Please insert total weight");
return;
}
CargoType cargo = await Navigator.push<CargoType>(
context,
CupertinoPageRoute(
builder: (context) => CargoTypeEditor(
cargo: c,
)));
if (widget.onAdd != null) widget.onAdd(cargo);
if (cargo == null) return;
this._cargos.add(cargo);
if (this.remainingWeight <= 0) return;
this.remainingWeight -= cargo.weight;
this._cargos.forEach((c) {
_list.add(c.name);
});
widget.cargoTypes.forEach((c) {
_types.add(c.name);
});
if (this._cargos.length == widget.cargoTypes.length - 1) {
_types.forEach((t) {
if (!_list.contains(t)) {
widget.cargoTypes.forEach((c) {
if (c.name == t) {
c.weight = this.remainingWeight;
}
});
}
});
}
},
onSelectChanged: (bool selected) async {},
cells: [
MyDataCell(new Text(
c.name == null ? "" : c.name,
style: textStyle,
MyDataCell(Row(
children: [
new Text(
c.name == null ? "" : c.name,
style: textStyle,
),
new Text(
c.qty == null ? "" : " x ${c.qty.toString()}",
style: TextStyle(color: Colors.grey),
),
],
)),
MyDataCell(
Row(
@@ -153,13 +134,35 @@ class _CargoTableState extends State<CargoTable> {
if (_t == null) return;
setState(() {
totalWeight = _t;
remainingWeight = _t;
this.remainingWeight = this.totalWeight - _total;
widget.cargoTypes.forEach((c) {
if (c.qty == null) {
this._cargos.add(c);
}
});
this._cargos.forEach((c) {
_list.add(c.name);
});
widget.cargoTypes.forEach((c) {
_types.add(c.name);
});
if (this._cargos.length == widget.cargoTypes.length - 1) {
_types.forEach((t) {
if (!_list.contains(t)) {
widget.cargoTypes.forEach((c) {
if (c.name == t) {
c.weight = this.remainingWeight;
}
});
}
});
}
});
},
child: Container(
padding: const EdgeInsets.all(7.0),
decoration: BoxDecoration(
border: Border.all(color: primaryColor),
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.all(Radius.circular(5.0)),
),
child: Text(totalWeight.toStringAsFixed(2),
@@ -178,78 +181,4 @@ class _CargoTableState extends State<CargoTable> {
double _r = this.totalWeight < total ? 0 : this.totalWeight - total;
return _r;
}
List<MyDataRow> _getCargoRows(BuildContext context) {
if (widget.cargoTypes == null) {
return [];
}
double total = 0;
var rows = widget.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,
)));
if (widget.onAdd != null) widget.onAdd(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.toStringAsFixed(2),
style: textStyle),
widget.onRemove == null
? SizedBox(
width: 50,
)
: IconButton(
icon: Icon(
Icons.remove_circle,
color: primaryColor,
),
onPressed: () {
if (widget.onRemove != null) widget.onRemove(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.toStringAsFixed(2),
style: TextStyle(fontWeight: FontWeight.bold))),
),
),
],
);
rows.add(totalRow);
return rows;
}
}

View File

@@ -99,11 +99,11 @@ class _CartonEditorState extends State<CartonEditor> {
_isNew = true;
_selectedCartonType = carton_from_packages;
_loadFcsShipments();
_cartons = [
Carton(cartonNumber: "A100B-1#1"),
Carton(cartonNumber: "A100B-1#2"),
Carton(cartonNumber: "A100B-1#3")
];
// _cartons = [
// Carton(cartonNumber: "A100B-1#1"),
// Carton(cartonNumber: "A100B-1#2"),
// Carton(cartonNumber: "A100B-1#3")
// ];
}
}
@@ -382,9 +382,13 @@ class _CartonEditorState extends State<CartonEditor> {
leading: new IconButton(
icon: new Icon(CupertinoIcons.back, color: primaryColor, size: 30),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
if (isDataChanged()) {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
} else {
Navigator.of(context).pop();
});
}
},
),
shadowColor: Colors.transparent,
@@ -726,4 +730,12 @@ class _CartonEditorState extends State<CartonEditor> {
});
}
}
isDataChanged() {
if (_isNew) {
return _fcsShipment != null || _user != null || _cartons.isNotEmpty;
} else {
return true;
}
}
}

View File

@@ -4,12 +4,15 @@ typedef OnAdd(String value);
class InputTextBorder extends StatelessWidget {
final OnAdd onAdd;
final TextEditingController controller;
const InputTextBorder({Key key, this.onAdd}) : super(key: key);
const InputTextBorder({Key key, this.onAdd, this.controller})
: super(key: key);
@override
Widget build(BuildContext context) {
return TextFormField(
textAlign: TextAlign.center,
controller: controller,
onChanged: (v) {
if (onAdd != null) onAdd(v);
},