From 20477b691569aac5957b841596d1c1669f1ec5af Mon Sep 17 00:00:00 2001 From: Thinzar Win Date: Tue, 8 Dec 2020 20:24:15 +0630 Subject: [PATCH] add prompt confirmation and update carton --- assets/local/localization_en.json | 3 +- assets/local/localization_mu.json | 3 +- lib/domain/entities/cargo_type.dart | 8 +- lib/domain/entities/carton_size.dart | 7 +- lib/domain/entities/custom_duty.dart | 11 +- lib/domain/entities/discount.dart | 6 + lib/domain/entities/discount_by_weight.dart | 5 + lib/domain/entities/fcs_shipment.dart | 10 ++ lib/domain/entities/package.dart | 6 + lib/domain/entities/processing.dart | 6 + lib/domain/entities/rate.dart | 6 + lib/domain/vo/delivery_address.dart | 9 + lib/pages/carton/cargo_type_addtion.dart | 108 +++++++---- lib/pages/carton/carton_cargo_table.dart | 165 +++++++++++++---- lib/pages/carton/carton_cargo_table_old.dart | 169 +++++------------- lib/pages/carton/carton_editor.dart | 26 ++- lib/pages/carton/input_text_border.dart | 5 +- lib/pages/carton_size/carton_size_editor.dart | 28 ++- lib/pages/contact/contact_editor.dart | 8 +- lib/pages/customer/invitation_create.dart | 14 +- lib/pages/delivery/delivery_info.dart | 4 +- .../delivery_address_editor.dart | 22 ++- lib/pages/discount/discount_editor.dart | 23 ++- lib/pages/faq/faq_edit_page.dart | 19 +- .../fcs_shipment/fcs_shipment_editor.dart | 24 ++- lib/pages/invoice/editor/invoice_editor.dart | 4 +- .../payment_method_editor.dart | 17 +- .../processing/processing_edit_editor.dart | 16 +- lib/pages/processing/processing_editor.dart | 18 +- lib/pages/profile/profile_currency_edit.dart | 4 +- lib/pages/profile/profile_edit.dart | 4 +- lib/pages/rates/cargo_editor.dart | 18 +- lib/pages/rates/custom_editor.dart | 36 +++- .../rates/discount_by_weight_editor.dart | 19 +- lib/pages/rates/shipment_rates_edit.dart | 19 +- lib/pages/receiving/receiving_editor.dart | 26 ++- lib/pages/shipment/shipment_editor.dart | 12 +- lib/pages/staff/staff_editor.dart | 4 +- lib/pages/term/term_edit.dart | 4 +- 39 files changed, 637 insertions(+), 259 deletions(-) diff --git a/assets/local/localization_en.json b/assets/local/localization_en.json index b0e84c9..5ed4227 100644 --- a/assets/local/localization_en.json +++ b/assets/local/localization_en.json @@ -13,7 +13,7 @@ "btn.ok": "Ok", "feet":"Feet", "inch":"Inch", - "back.button_confirm":"Are you sure you want to continue without saving changes?", + "back.button_confirm":"Are you sure you want to continue without submitting changes?", "Buttons End ================================================================":"", "Offline Start ================================================================":"", @@ -405,6 +405,7 @@ "rate.custom.form.title":"Custom", "rate.cutom.product_type":"Product type", "rate.custom.fee":"Fee", + "rate.custom.shipment_rate":"Shipment rate", "rate.discount.weight":"Weight", "rate.discount.rate":"Discount rate", "rate.custom_duty.title":"Custom Fee", diff --git a/assets/local/localization_mu.json b/assets/local/localization_mu.json index 5882d12..1fa9c3e 100644 --- a/assets/local/localization_mu.json +++ b/assets/local/localization_mu.json @@ -12,7 +12,7 @@ "btn.ok": "အိုကေ", "feet":"ပေ", "inch":"လက်မ", - "back.button_confirm":"Are you sure you want to continue without saving changes?", + "back.button_confirm":"Are you sure you want to continue without submitting changes?", "Buttons End ================================================================":"", "Offline Start ================================================================":"", @@ -405,6 +405,7 @@ "rate.custom.form.title":"အကောက်ခွန်", "rate.cutom.product_type":"ကုန်ပစ္စည်းအမျိုးအစား", "rate.custom.fee":"အခကြေးငွေ", + "rate.custom.shipment_rate":"တင်ပို့နှုန်း", "rate.discount.weight":"အလေးချိန်", "rate.discount.rate":"လျှော့စျေးနှုန်း", "rate.custom_duty.title":"အကောက်ခွန်များ", diff --git a/lib/domain/entities/cargo_type.dart b/lib/domain/entities/cargo_type.dart index f1da842..76ccfe2 100644 --- a/lib/domain/entities/cargo_type.dart +++ b/lib/domain/entities/cargo_type.dart @@ -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 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; + } } diff --git a/lib/domain/entities/carton_size.dart b/lib/domain/entities/carton_size.dart index 91910ef..2587bdf 100644 --- a/lib/domain/entities/carton_size.dart +++ b/lib/domain/entities/carton_size.dart @@ -6,7 +6,6 @@ class CartonSize { double height; CartonSize({this.id, this.name, this.length, this.width, this.height}); - Map 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; + } } diff --git a/lib/domain/entities/custom_duty.dart b/lib/domain/entities/custom_duty.dart index d5eba6a..fb2a3aa 100644 --- a/lib/domain/entities/custom_duty.dart +++ b/lib/domain/entities/custom_duty.dart @@ -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 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 + ; + } } diff --git a/lib/domain/entities/discount.dart b/lib/domain/entities/discount.dart index 1815a72..cb2bda0 100644 --- a/lib/domain/entities/discount.dart +++ b/lib/domain/entities/discount.dart @@ -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; + } } diff --git a/lib/domain/entities/discount_by_weight.dart b/lib/domain/entities/discount_by_weight.dart index cc4b179..3ff9a1d 100644 --- a/lib/domain/entities/discount_by_weight.dart +++ b/lib/domain/entities/discount_by_weight.dart @@ -20,4 +20,9 @@ class DiscountByWeight { 'discount': discount, }; } + + bool isChangedForEdit(DiscountByWeight discountByWeight) { + return discountByWeight.weight != this.weight || + discountByWeight.discount != this.discount; + } } diff --git a/lib/domain/entities/fcs_shipment.dart b/lib/domain/entities/fcs_shipment.dart index adfc4f2..37e2c71 100644 --- a/lib/domain/entities/fcs_shipment.dart +++ b/lib/domain/entities/fcs_shipment.dart @@ -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; + } } diff --git a/lib/domain/entities/package.dart b/lib/domain/entities/package.dart index e03c814..65ae83a 100644 --- a/lib/domain/entities/package.dart +++ b/lib/domain/entities/package.dart @@ -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; diff --git a/lib/domain/entities/processing.dart b/lib/domain/entities/processing.dart index f801903..0006183 100644 --- a/lib/domain/entities/processing.dart +++ b/lib/domain/entities/processing.dart @@ -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}'; diff --git a/lib/domain/entities/rate.dart b/lib/domain/entities/rate.dart index 94a1ec4..3719978 100644 --- a/lib/domain/entities/rate.dart +++ b/lib/domain/entities/rate.dart @@ -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}'; diff --git a/lib/domain/vo/delivery_address.dart b/lib/domain/vo/delivery_address.dart index b7157bb..a0c507e 100644 --- a/lib/domain/vo/delivery_address.dart +++ b/lib/domain/vo/delivery_address.dart @@ -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; + } } diff --git a/lib/pages/carton/cargo_type_addtion.dart b/lib/pages/carton/cargo_type_addtion.dart index c91e022..7dbf934 100644 --- a/lib/pages/carton/cargo_type_addtion.dart +++ b/lib/pages/carton/cargo_type_addtion.dart @@ -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 { @override void initState() { super.initState(); - cargos = - Provider.of(context, listen: false).rate.cargoTypes; + var shipmentRateModel = + Provider.of(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 { ), ), SizedBox( - width: 50, + width: 40, ), LocalText( context, @@ -95,40 +98,58 @@ class _CargoTypeAdditionState extends State { }), 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 { Navigator.pop(context, _cargos); }, ); + return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( @@ -169,7 +191,21 @@ class _CargoTypeAdditionState extends State { child: ListView( shrinkWrap: true, children: [ - 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 { ), ); } + + _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)); + }); + } } diff --git a/lib/pages/carton/carton_cargo_table.dart b/lib/pages/carton/carton_cargo_table.dart index 159f9e2..e820133 100644 --- a/lib/pages/carton/carton_cargo_table.dart +++ b/lib/pages/carton/carton_cargo_table.dart @@ -28,8 +28,13 @@ class _CargoTableState extends State { double totalWeight = 0; List _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 { ), ), 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 { } List _list = []; List _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( + 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 { 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 { 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 { double _r = this.totalWeight < total ? 0 : this.totalWeight - total; return _r; } + + List _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( + 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; + } } diff --git a/lib/pages/carton/carton_cargo_table_old.dart b/lib/pages/carton/carton_cargo_table_old.dart index 97dc6a5..9333dae 100644 --- a/lib/pages/carton/carton_cargo_table_old.dart +++ b/lib/pages/carton/carton_cargo_table_old.dart @@ -41,10 +41,17 @@ class _CargoTableState extends State { ), ), 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 { } List _list = []; List _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( - 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 { 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 { double _r = this.totalWeight < total ? 0 : this.totalWeight - total; return _r; } - - List _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( - 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; - } } diff --git a/lib/pages/carton/carton_editor.dart b/lib/pages/carton/carton_editor.dart index e1f6aed..f6ebfdd 100644 --- a/lib/pages/carton/carton_editor.dart +++ b/lib/pages/carton/carton_editor.dart @@ -99,11 +99,11 @@ class _CartonEditorState extends State { _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 { 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 { }); } } + + isDataChanged() { + if (_isNew) { + return _fcsShipment != null || _user != null || _cartons.isNotEmpty; + } else { + return true; + } + } } diff --git a/lib/pages/carton/input_text_border.dart b/lib/pages/carton/input_text_border.dart index 949c00d..58f2314 100644 --- a/lib/pages/carton/input_text_border.dart +++ b/lib/pages/carton/input_text_border.dart @@ -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); }, diff --git a/lib/pages/carton_size/carton_size_editor.dart b/lib/pages/carton_size/carton_size_editor.dart index 06eb228..0b3662b 100644 --- a/lib/pages/carton_size/carton_size_editor.dart +++ b/lib/pages/carton_size/carton_size_editor.dart @@ -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 { 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 { ), ); } + + 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); + } + } } diff --git a/lib/pages/contact/contact_editor.dart b/lib/pages/contact/contact_editor.dart index a9c8eee..5a7cf50 100644 --- a/lib/pages/contact/contact_editor.dart +++ b/lib/pages/contact/contact_editor.dart @@ -29,17 +29,21 @@ class _ContactEditorState extends State { 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 { 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, diff --git a/lib/pages/customer/invitation_create.dart b/lib/pages/customer/invitation_create.dart index 318686d..51fd10c 100644 --- a/lib/pages/customer/invitation_create.dart +++ b/lib/pages/customer/invitation_create.dart @@ -52,9 +52,13 @@ class _InvitationCreateState extends State { 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 { }); } } + + isDataChanged() { + String userName = _nameController.text; + String phoneNumber = _phoneController.text; + return userName != "" || phoneNumber != ""; + } } diff --git a/lib/pages/delivery/delivery_info.dart b/lib/pages/delivery/delivery_info.dart index 2151cba..f9fecd2 100644 --- a/lib/pages/delivery/delivery_info.dart +++ b/lib/pages/delivery/delivery_info.dart @@ -238,9 +238,7 @@ class _DeliveryInfoState extends State { 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, diff --git a/lib/pages/delivery_address/delivery_address_editor.dart b/lib/pages/delivery_address/delivery_address_editor.dart index 78ac361..26bbccd 100644 --- a/lib/pages/delivery_address/delivery_address_editor.dart +++ b/lib/pages/delivery_address/delivery_address_editor.dart @@ -107,9 +107,13 @@ class _DeliveryAddressEditorState extends State { 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 { }); } } + + 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); + } + } } diff --git a/lib/pages/discount/discount_editor.dart b/lib/pages/discount/discount_editor.dart index a680dba..d28856f 100644 --- a/lib/pages/discount/discount_editor.dart +++ b/lib/pages/discount/discount_editor.dart @@ -98,9 +98,13 @@ class _DiscountEditorState extends State { 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 { }); } } + + 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); + } + } } diff --git a/lib/pages/faq/faq_edit_page.dart b/lib/pages/faq/faq_edit_page.dart index aee3a4c..73045be 100644 --- a/lib/pages/faq/faq_edit_page.dart +++ b/lib/pages/faq/faq_edit_page.dart @@ -127,9 +127,13 @@ class _FAQEditorState extends State { 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 { }); } } + + isDataChanged() { + return _sn.text != "" || + _engQ.text != "" || + _engA.text != "" || + _mmQ.text != "" || + _mmA.text != "" || + _pageLabelEng.text != "" || + _pageLabelMm.text != "" || + _pageLink != info; + } } diff --git a/lib/pages/fcs_shipment/fcs_shipment_editor.dart b/lib/pages/fcs_shipment/fcs_shipment_editor.dart index 2c02a43..82feb2e 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_editor.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_editor.dart @@ -94,9 +94,13 @@ class _FcsShipmentEditorState extends State { 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 { }); } } + + isDataChanged() { + if (_isNew) { + var mainModel = Provider.of(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); + } + } } diff --git a/lib/pages/invoice/editor/invoice_editor.dart b/lib/pages/invoice/editor/invoice_editor.dart index 8bab876..16f3420 100644 --- a/lib/pages/invoice/editor/invoice_editor.dart +++ b/lib/pages/invoice/editor/invoice_editor.dart @@ -316,9 +316,7 @@ class _InvoiceEditorState extends State { 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, diff --git a/lib/pages/payment_methods/payment_method_editor.dart b/lib/pages/payment_methods/payment_method_editor.dart index 334b0ef..9118cdf 100644 --- a/lib/pages/payment_methods/payment_method_editor.dart +++ b/lib/pages/payment_methods/payment_method_editor.dart @@ -61,9 +61,13 @@ class _PaymentMethodEditorState extends State { 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 { }); } } + + isDataChanged() { + return _nameController.text != "" || + _accountNameController.text != "" || + _accountNumberController.text != "" || + _phoneController.text != "" || + _mailController.text != "" || + _linkController.text != ""; + } } diff --git a/lib/pages/processing/processing_edit_editor.dart b/lib/pages/processing/processing_edit_editor.dart index 858f9bc..908dbd4 100644 --- a/lib/pages/processing/processing_edit_editor.dart +++ b/lib/pages/processing/processing_edit_editor.dart @@ -118,9 +118,13 @@ class _ProcessingEditEditorState extends State { 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 { }); } } + + isDataChanged() { + return _user.fcsID != "" || + selectedMarket != "" || + _descCtl.text != "" || + _remarkCtl.text != "" || + multiImgController.getAddedFile.isNotEmpty; + } } diff --git a/lib/pages/processing/processing_editor.dart b/lib/pages/processing/processing_editor.dart index 6b3b5fc..84fd726 100644 --- a/lib/pages/processing/processing_editor.dart +++ b/lib/pages/processing/processing_editor.dart @@ -172,9 +172,13 @@ class _ProcesingEditorState extends State { 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 { }); } } + + 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); + } + } } diff --git a/lib/pages/profile/profile_currency_edit.dart b/lib/pages/profile/profile_currency_edit.dart index 6e8aeb6..92fe1c8 100644 --- a/lib/pages/profile/profile_currency_edit.dart +++ b/lib/pages/profile/profile_currency_edit.dart @@ -60,9 +60,7 @@ class _ProfileCurrencyEditState extends State { color: primaryColor, ), onPressed: () { - showConfirmDialog(context, "back.button_confirm", () { - Navigator.of(context).pop(); - }); + Navigator.of(context).pop(); }, ), ), diff --git a/lib/pages/profile/profile_edit.dart b/lib/pages/profile/profile_edit.dart index 8cd33f8..a4ab671 100644 --- a/lib/pages/profile/profile_edit.dart +++ b/lib/pages/profile/profile_edit.dart @@ -75,9 +75,7 @@ class _ProfileEditState extends State { color: primaryColor, ), onPressed: () { - showConfirmDialog(context, "back.button_confirm", () { - Navigator.of(context).pop(); - }); + Navigator.of(context).pop(); }, ), ), diff --git a/lib/pages/rates/cargo_editor.dart b/lib/pages/rates/cargo_editor.dart index 59cf820..d084754 100644 --- a/lib/pages/rates/cargo_editor.dart +++ b/lib/pages/rates/cargo_editor.dart @@ -61,9 +61,13 @@ class _CargoEditorState extends State { 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 { }); } } + + 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); + } + } } diff --git a/lib/pages/rates/custom_editor.dart b/lib/pages/rates/custom_editor.dart index b97cd9f..9633fb2 100644 --- a/lib/pages/rates/custom_editor.dart +++ b/lib/pages/rates/custom_editor.dart @@ -22,6 +22,7 @@ class CustomEditor extends StatefulWidget { class _CustomEditorState extends State { 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 { _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 { 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 { 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 { children: [ productBox, feeBox, + shipmentRateBox, SizedBox(height: 30), ], ), @@ -111,7 +125,8 @@ class _CustomEditorState extends State { Provider.of(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 { }); } } + + 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); + } + } } diff --git a/lib/pages/rates/discount_by_weight_editor.dart b/lib/pages/rates/discount_by_weight_editor.dart index 487d4fa..973d156 100644 --- a/lib/pages/rates/discount_by_weight_editor.dart +++ b/lib/pages/rates/discount_by_weight_editor.dart @@ -63,9 +63,13 @@ class _DiscountByWeightEditorState extends State { 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 { }); } } + + 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); + } + } } diff --git a/lib/pages/rates/shipment_rates_edit.dart b/lib/pages/rates/shipment_rates_edit.dart index 1595166..49f338a 100644 --- a/lib/pages/rates/shipment_rates_edit.dart +++ b/lib/pages/rates/shipment_rates_edit.dart @@ -29,13 +29,14 @@ class _ShipmentRatesEditState extends State { TextEditingController _minWeight = new TextEditingController(); TextEditingController _deliveryFee = new TextEditingController(); TextEditingController _volumetricRatio = new TextEditingController(); + Rate rate; @override void initState() { super.initState(); var shipmentRateModel = Provider.of(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 { 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 { } } + 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 getCargoRows(List cargos) { return cargos.map((r) { return MyDataRow( diff --git a/lib/pages/receiving/receiving_editor.dart b/lib/pages/receiving/receiving_editor.dart index 78bb9a3..f9c670f 100644 --- a/lib/pages/receiving/receiving_editor.dart +++ b/lib/pages/receiving/receiving_editor.dart @@ -150,9 +150,13 @@ class _ReceivingEditorState extends State { 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 { }); } } + + 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; + } + } } diff --git a/lib/pages/shipment/shipment_editor.dart b/lib/pages/shipment/shipment_editor.dart index f3c6aa6..0dbc141 100644 --- a/lib/pages/shipment/shipment_editor.dart +++ b/lib/pages/shipment/shipment_editor.dart @@ -166,9 +166,13 @@ class _ShipmentEditorState extends State { 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 { MainModel mainModel = Provider.of(context, listen: false); launch("${mainModel.setting.courierWebsite}"); } + + isDataChanged() { + return _shipment.boxes.isNotEmpty; + } } diff --git a/lib/pages/staff/staff_editor.dart b/lib/pages/staff/staff_editor.dart index 1cad728..4812c32 100644 --- a/lib/pages/staff/staff_editor.dart +++ b/lib/pages/staff/staff_editor.dart @@ -174,9 +174,7 @@ class _StaffEditorState extends State { 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, diff --git a/lib/pages/term/term_edit.dart b/lib/pages/term/term_edit.dart index 571b3e0..2a5c188 100644 --- a/lib/pages/term/term_edit.dart +++ b/lib/pages/term/term_edit.dart @@ -77,9 +77,7 @@ class _TermEditState extends State { size: 30, ), onPressed: () { - showConfirmDialog(context, "back.button_confirm", () { - Navigator.of(context).pop(); - }); + Navigator.of(context).pop(); }, ), shadowColor: Colors.transparent,