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

@@ -5,6 +5,7 @@ class CargoType {
double weight;
bool isChecked;
int qty;
bool isCutomDuty = false;
double get calAmount => (calRate ?? 0) * (calWeight ?? 0);
@@ -29,7 +30,8 @@ class CargoType {
this.calWeight,
this.calRate,
this.isChecked = false,
this.qty = 0});
this.qty = 0,
this.isCutomDuty = false});
Map<String, dynamic> toMap() {
return {
@@ -56,4 +58,8 @@ class CargoType {
String toString() {
return name;
}
bool isChangedForEdit(CargoType cargoType) {
return cargoType.name != this.name || cargoType.rate != this.rate;
}
}

View File

@@ -6,7 +6,6 @@ class CartonSize {
double height;
CartonSize({this.id, this.name, this.length, this.width, this.height});
Map<String, dynamic> toMap() {
return {
'id': id,
@@ -27,4 +26,10 @@ class CartonSize {
);
}
bool isChangedForEdit(CartonSize cartonSize) {
return cartonSize.name != this.name ||
cartonSize.length != this.length ||
cartonSize.width != this.width ||
cartonSize.height != this.height;
}
}

View File

@@ -3,7 +3,9 @@ class CustomDuty {
String productType;
String desc;
double fee;
CustomDuty({this.id, this.productType, this.desc, this.fee});
double shipmentRate;
CustomDuty(
{this.id, this.productType, this.desc, this.fee, this.shipmentRate});
factory CustomDuty.fromMap(Map<String, dynamic> map, String id) {
return CustomDuty(
@@ -28,4 +30,11 @@ class CustomDuty {
@override
int get hashCode => id.hashCode;
bool isChangedForEdit(CustomDuty customDuty) {
return customDuty.productType != this.productType ||
customDuty.fee != this.fee
// ||customDuty.shipmentRate != this.shipmentRate
;
}
}

View File

@@ -35,4 +35,10 @@ class Discount {
status: map['status'],
);
}
bool isChangedForEdit(Discount discount) {
return discount.code != this.code ||
discount.amount != this.amount ||
discount.customerId != this.customerId;
}
}

View File

@@ -20,4 +20,9 @@ class DiscountByWeight {
'discount': discount,
};
}
bool isChangedForEdit(DiscountByWeight discountByWeight) {
return discountByWeight.weight != this.weight ||
discountByWeight.discount != this.discount;
}
}

View File

@@ -66,4 +66,14 @@ class FcsShipment {
bool isConfirmed() {
return status == fcs_shipment_confirmed_status;
}
bool isChangedForEdit(FcsShipment fcsShipment) {
return fcsShipment.shipmentNumber != this.shipmentNumber ||
fcsShipment.cutoffDate != this.cutoffDate ||
fcsShipment.arrivalDate != this.arrivalDate ||
fcsShipment.shipType != this.shipType ||
fcsShipment.consignee != this.consignee ||
fcsShipment.port != this.port ||
fcsShipment.destination != this.destination;
}
}

View File

@@ -131,6 +131,12 @@ class Package {
currentStatusDate: DateTime.parse(json['status_date']));
}
bool isChangedForEdit(Package package) {
return package.trackingID != this.trackingID ||
package.remark != this.remark ||
package.fcsID != this.fcsID;
}
@override
bool operator ==(Object other) => other is Package && other.id == id;

View File

@@ -29,6 +29,12 @@ class Processing {
@override
int get hashCode => id.hashCode;
bool isChangedForEdit(Processing processing) {
return processing.userID != this.userID ||
processing.fcsID != this.fcsID ||
processing.packages != this.packages;
}
@override
String toString() {
return 'Processing{id: $id}';

View File

@@ -44,6 +44,12 @@ class Rate {
};
}
bool isChangedForEdit(Rate rate) {
return rate.freeDeliveryWeight != this.freeDeliveryWeight ||
rate.deliveryFee != this.deliveryFee ||
rate.volumetricRatio != this.volumetricRatio;
}
@override
String toString() {
return 'Rate{deliveryFee:$deliveryFee,freeDeliveryWeight:$freeDeliveryWeight,volumetricRatio:$volumetricRatio}';

View File

@@ -41,4 +41,13 @@ class DeliveryAddress {
'phone_number': phoneNumber,
};
}
bool isChangedForEdit(DeliveryAddress deliveryAddress) {
return deliveryAddress.fullName != this.fullName ||
deliveryAddress.phoneNumber != this.phoneNumber ||
deliveryAddress.addressLine1 != this.addressLine1 ||
deliveryAddress.addressLine2 != this.addressLine2 ||
deliveryAddress.state != this.state ||
deliveryAddress.city != this.city;
}
}

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);
},

View File

@@ -1,11 +1,8 @@
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/carton_size.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
import 'package:fcs/pages/widgets/input_text.dart';
import 'package:fcs/pages/widgets/length_picker.dart';
import 'package:fcs/pages/widgets/local_dropdown.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
@@ -140,9 +137,13 @@ class _CartonSizeEditorState extends State<CartonSizeEditor> {
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,
@@ -169,4 +170,21 @@ class _CartonSizeEditorState extends State<CartonSizeEditor> {
),
);
}
isDataChanged() {
if (_isNew) {
return _nameController.text != "" ||
_lengthController.text != "12" ||
_widthController.text != "12" ||
_heightController.text != "12";
} else {
double l = double.parse(_lengthController.text, (s) => 0);
double w = double.parse(_widthController.text, (s) => 0);
double h = double.parse(_heightController.text, (s) => 0);
CartonSize _cartonSize = CartonSize(
name: _nameController.text, length: l, width: w, height: h);
return widget.cartonSize.isChangedForEdit(_cartonSize);
}
}
}

View File

@@ -29,17 +29,21 @@ class _ContactEditorState extends State<ContactEditor> {
TextEditingController _facebook = new TextEditingController();
bool _isLoading = false;
bool isNew;
@override
void initState() {
super.initState();
if (widget.contact != null) {
isNew = false;
_usaPhone.text = widget.contact.usaContactNumber;
_mmPhone.text = widget.contact.mmContactNumber;
_usaAddress.text = widget.contact.usaAddress;
_mmAddress.text = widget.contact.mmAddress;
_email.text = widget.contact.emailAddress;
_facebook.text = widget.contact.facebookLink;
} else {
isNew = true;
}
}
@@ -83,9 +87,7 @@ class _ContactEditorState extends State<ContactEditor> {
leading: new IconButton(
icon: new Icon(CupertinoIcons.back, color: primaryColor),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
Navigator.of(context).pop();
}),
shadowColor: Colors.transparent,
backgroundColor: Colors.white,

View File

@@ -52,9 +52,13 @@ class _InvitationCreateState extends State<InvitationCreate> {
color: primaryColor,
),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
if (isDataChanged()) {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
} else {
Navigator.of(context).pop();
});
}
},
),
title: LocalText(
@@ -166,4 +170,10 @@ class _InvitationCreateState extends State<InvitationCreate> {
});
}
}
isDataChanged() {
String userName = _nameController.text;
String phoneNumber = _phoneController.text;
return userName != "" || phoneNumber != "";
}
}

View File

@@ -238,9 +238,7 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
leading: new IconButton(
icon: new Icon(CupertinoIcons.back, color: primaryColor, size: 30),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
Navigator.of(context).pop();
},
),
shadowColor: Colors.transparent,

View File

@@ -107,9 +107,13 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
leading: new IconButton(
icon: new Icon(CupertinoIcons.back, color: primaryColor),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
if (isDataChanged()) {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
} else {
Navigator.of(context).pop();
});
}
},
),
backgroundColor: Colors.white,
@@ -252,4 +256,18 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
});
}
}
isDataChanged() {
if (_isNew) {
return _nameController.text != "" ||
_phoneController.text != "" ||
_address1Controller.text != "" ||
_address2Controller.text != "" ||
_cityController.text != "Yangon" ||
_stateController.text != "Yangon";
} else {
DeliveryAddress deliveryAddress = _getPayload();
return widget.deliveryAddress.isChangedForEdit(deliveryAddress);
}
}
}

View File

@@ -98,9 +98,13 @@ class _DiscountEditorState extends State<DiscountEditor> {
leading: new IconButton(
icon: new Icon(CupertinoIcons.back),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
if (isDataChanged()) {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
} else {
Navigator.of(context).pop();
});
}
},
),
backgroundColor: primaryColor,
@@ -192,4 +196,19 @@ class _DiscountEditorState extends State<DiscountEditor> {
});
}
}
isDataChanged() {
if (_isNew) {
return _codeController.text != "" ||
_amountController.text != "" ||
customerName != "";
} else {
Discount _discount = Discount(
code: _codeController.text,
customerName: customerName,
customerId: customerId,
amount: double.parse(_amountController.text));
return widget.discount.isChangedForEdit(_discount);
}
}
}

View File

@@ -127,9 +127,13 @@ class _FAQEditorState extends State<FAQEditor> {
leading: new IconButton(
icon: new Icon(CupertinoIcons.back, color: primaryColor),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
if (isDataChanged()) {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
} else {
Navigator.of(context).pop();
});
}
},
),
backgroundColor: Colors.white,
@@ -240,4 +244,15 @@ class _FAQEditorState extends State<FAQEditor> {
});
}
}
isDataChanged() {
return _sn.text != "" ||
_engQ.text != "" ||
_engA.text != "" ||
_mmQ.text != "" ||
_mmA.text != "" ||
_pageLabelEng.text != "" ||
_pageLabelMm.text != "" ||
_pageLink != info;
}
}

View File

@@ -94,9 +94,13 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
leading: new IconButton(
icon: new Icon(CupertinoIcons.back, color: primaryColor),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
if (isDataChanged()) {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
} else {
Navigator.of(context).pop();
});
}
},
),
backgroundColor: Colors.white,
@@ -271,4 +275,20 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
});
}
}
isDataChanged() {
if (_isNew) {
var mainModel = Provider.of<MainModel>(context, listen: false);
return _shipmentNumberController.text != "" ||
_cutoffDateController.text != "" ||
_arrivalDateController.text != "" ||
_consigneeController.text != "" ||
_portController.text != "" ||
_destinationController.text != "" ||
_currentShipmentType != mainModel.setting.shipmentTypes[0];
} else {
FcsShipment fcsShipment = _getPayload();
return widget.shipment.isChangedForEdit(fcsShipment);
}
}
}

View File

@@ -316,9 +316,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
leading: new IconButton(
icon: new Icon(CupertinoIcons.back, color: primaryColor),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
Navigator.of(context).pop();
},
),
backgroundColor: Colors.white,

View File

@@ -61,9 +61,13 @@ class _PaymentMethodEditorState extends State<PaymentMethodEditor> {
leading: new IconButton(
icon: new Icon(CupertinoIcons.back, color: primaryColor),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
if (isDataChanged()) {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
} else {
Navigator.of(context).pop();
});
}
},
),
title: LocalText(
@@ -214,4 +218,13 @@ class _PaymentMethodEditorState extends State<PaymentMethodEditor> {
});
}
}
isDataChanged() {
return _nameController.text != "" ||
_accountNameController.text != "" ||
_accountNumberController.text != "" ||
_phoneController.text != "" ||
_mailController.text != "" ||
_linkController.text != "";
}
}

View File

@@ -118,9 +118,13 @@ class _ProcessingEditEditorState extends State<ProcessingEditEditor> {
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,
@@ -261,4 +265,12 @@ class _ProcessingEditEditorState extends State<ProcessingEditEditor> {
});
}
}
isDataChanged() {
return _user.fcsID != "" ||
selectedMarket != "" ||
_descCtl.text != "" ||
_remarkCtl.text != "" ||
multiImgController.getAddedFile.isNotEmpty;
}
}

View File

@@ -172,9 +172,13 @@ class _ProcesingEditorState extends State<ProcesingEditor> {
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,
@@ -324,4 +328,14 @@ class _ProcesingEditorState extends State<ProcesingEditor> {
});
}
}
isDataChanged() {
if (_isNew) {
return this.packages.isNotEmpty || user != null || shipper != null;
} else {
Processing _processing = Processing(
userID: user.fcsID, fcsID: shipper.fcsID, packages: this.packages);
return widget.processing.isChangedForEdit(_processing);
}
}
}

View File

@@ -60,9 +60,7 @@ class _ProfileCurrencyEditState extends State<ProfileCurrencyEdit> {
color: primaryColor,
),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
Navigator.of(context).pop();
},
),
),

View File

@@ -75,9 +75,7 @@ class _ProfileEditState extends State<ProfileEdit> {
color: primaryColor,
),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
Navigator.of(context).pop();
},
),
),

View File

@@ -61,9 +61,13 @@ class _CargoEditorState extends State<CargoEditor> {
leading: new IconButton(
icon: new Icon(CupertinoIcons.back),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
if (isDataChanged()) {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
} else {
Navigator.of(context).pop();
});
}
},
),
backgroundColor: primaryColor,
@@ -144,4 +148,14 @@ class _CargoEditorState extends State<CargoEditor> {
});
}
}
isDataChanged() {
if (_isNew) {
return _descController.text != "" || _rateController.text != "";
} else {
CargoType _cargo = CargoType(
name: _descController.text, rate: double.parse(_rateController.text));
return widget.cargo.isChangedForEdit(_cargo);
}
}
}

View File

@@ -22,6 +22,7 @@ class CustomEditor extends StatefulWidget {
class _CustomEditorState extends State<CustomEditor> {
TextEditingController _productController = new TextEditingController();
TextEditingController _feeController = new TextEditingController();
TextEditingController _shipmentRateController = new TextEditingController();
bool _isLoading = false;
CustomDuty _custom = new CustomDuty();
@@ -34,6 +35,9 @@ class _CustomEditorState extends State<CustomEditor> {
_custom = widget.custom;
_productController.text = _custom.productType;
_feeController.text = _custom.fee.toStringAsFixed(2);
_shipmentRateController.text = _custom.shipmentRate == null
? ""
: _custom.shipmentRate.toStringAsFixed(2);
} else {
_isNew = true;
}
@@ -54,6 +58,11 @@ class _CustomEditorState extends State<CustomEditor> {
labelTextKey: 'rate.custom.fee',
iconData: Icons.attach_money,
controller: _feeController);
final shipmentRateBox = InputText(
labelTextKey: 'rate.custom.shipment_rate',
iconData: Icons.attach_money,
controller: _shipmentRateController);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
@@ -64,9 +73,13 @@ class _CustomEditorState extends State<CustomEditor> {
CupertinoIcons.back,
),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
if (isDataChanged()) {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
} else {
Navigator.of(context).pop();
});
}
},
),
backgroundColor: primaryColor,
@@ -88,6 +101,7 @@ class _CustomEditorState extends State<CustomEditor> {
children: <Widget>[
productBox,
feeBox,
shipmentRateBox,
SizedBox(height: 30),
],
),
@@ -111,7 +125,8 @@ class _CustomEditorState extends State<CustomEditor> {
Provider.of<ShipmentRateModel>(context, listen: false);
CustomDuty _customduty = CustomDuty(
productType: _productController.text,
fee: double.parse(_feeController.text));
fee: double.parse(_feeController.text),
shipmentRate: double.parse(_shipmentRateController.text));
print('_customduty => $_customduty');
if (_isNew) {
await shipmentRateModel.addCustomDuty(_customduty);
@@ -151,4 +166,19 @@ class _CustomEditorState extends State<CustomEditor> {
});
}
}
isDataChanged() {
if (_isNew) {
return _productController.text != "" ||
_feeController.text != "" ||
_shipmentRateController.text != "";
} else {
CustomDuty _customduty = CustomDuty(
productType: _productController.text,
fee: double.parse(_feeController.text),
// shipmentRate: double.parse(_shipmentRateController.text)
);
return widget.custom.isChangedForEdit(_customduty);
}
}
}

View File

@@ -63,9 +63,13 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
leading: new IconButton(
icon: new Icon(CupertinoIcons.back),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
if (isDataChanged()) {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
} else {
Navigator.of(context).pop();
});
}
},
),
backgroundColor: primaryColor,
@@ -149,4 +153,15 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
});
}
}
isDataChanged() {
if (_isNew) {
return _weightController.text != "" || _discountController.text != "";
} else {
DiscountByWeight _discount = DiscountByWeight(
weight: double.parse(_weightController.text),
discount: double.parse(_discountController.text));
return widget.discountByWeight.isChangedForEdit(_discount);
}
}
}

View File

@@ -29,13 +29,14 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
TextEditingController _minWeight = new TextEditingController();
TextEditingController _deliveryFee = new TextEditingController();
TextEditingController _volumetricRatio = new TextEditingController();
Rate rate;
@override
void initState() {
super.initState();
var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
Rate rate = shipmentRateModel.rate;
rate = shipmentRateModel.rate;
_minWeight.text = rate.freeDeliveryWeight?.toStringAsFixed(2) ?? "";
_deliveryFee.text = rate.deliveryFee?.toStringAsFixed(2) ?? "";
@@ -74,9 +75,13 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
CupertinoIcons.back,
),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
if (isDataChanged()) {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
} else {
Navigator.of(context).pop();
});
}
},
),
backgroundColor: primaryColor,
@@ -130,6 +135,14 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
}
}
isDataChanged() {
Rate _rate = new Rate(
deliveryFee: double.parse(_deliveryFee.text),
freeDeliveryWeight: double.parse(_minWeight.text),
volumetricRatio: double.parse(_volumetricRatio.text));
return rate.isChangedForEdit(_rate);
}
List<MyDataRow> getCargoRows(List<CargoType> cargos) {
return cargos.map((r) {
return MyDataRow(

View File

@@ -150,9 +150,13 @@ class _ReceivingEditorState extends State<ReceivingEditor> {
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,
@@ -253,4 +257,22 @@ class _ReceivingEditorState extends State<ReceivingEditor> {
});
}
}
isDataChanged() {
if (_isNew) {
return _trackingIDCtl.text != "" ||
_remarkCtl.text != "" ||
user != null ||
_multiImgController.getAddedFile.isNotEmpty;
} else {
var _package = Package(
trackingID: _trackingIDCtl.text,
remark: _remarkCtl.text,
fcsID: user.fcsID,
photoUrls: widget.package.photoUrls);
return widget.package.isChangedForEdit(_package) ||
_multiImgController.getAddedFile.isNotEmpty ||
_multiImgController.getDeletedUrl.isNotEmpty;
}
}
}

View File

@@ -166,9 +166,13 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
color: primaryColor,
),
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,
@@ -316,4 +320,8 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
launch("${mainModel.setting.courierWebsite}");
}
isDataChanged() {
return _shipment.boxes.isNotEmpty;
}
}

View File

@@ -174,9 +174,7 @@ class _StaffEditorState extends State<StaffEditor> {
icon: new Icon(CupertinoIcons.back,
color: primaryColor, size: 30),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
Navigator.of(context).pop();
}),
shadowColor: Colors.transparent,
backgroundColor: Colors.white,

View File

@@ -77,9 +77,7 @@ class _TermEditState extends State<TermEdit> {
size: 30,
),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
Navigator.of(context).pop();
},
),
shadowColor: Colors.transparent,