diff --git a/assets/local/localization_en.json b/assets/local/localization_en.json index bf1d8ed..2ad5e19 100644 --- a/assets/local/localization_en.json +++ b/assets/local/localization_en.json @@ -78,7 +78,7 @@ "FAQ Start ================================================================":"", "faq.btn":"FAQs", - "faq.title":"Frequently Asked Questions", + "faq.title":"FAQs", "faq.add.title":"New FAQ", "faq.edit.title":"Edit FAQ", "faq.edit.eng":"English", diff --git a/lib/data/provider/auth_fb.dart b/lib/data/provider/auth_fb.dart index bea0d16..4b5a0d0 100644 --- a/lib/data/provider/auth_fb.dart +++ b/lib/data/provider/auth_fb.dart @@ -132,6 +132,8 @@ class AuthFb { String privileges = idToken.claims["pr"]; if (privileges != null && privileges != "") { user.privileges = privileges.split(":").toList(); + } else { + user.privileges = []; } controller.add(user); } @@ -198,18 +200,6 @@ class AuthFb { return token.token; } - Future getSetting() async { - var snap = await Firestore.instance - .collection(config_collection) - .document(setting_doc_id) - .get(); - if (!snap.exists) { - return null; - } - // _listSetting(); - return Setting.fromMap(snap.data); - } - Stream settings() async* { Stream snapshot = Firestore.instance .collection(config_collection) diff --git a/lib/data/provider/rate_data_provider.dart b/lib/data/provider/rate_data_provider.dart new file mode 100644 index 0000000..a63dcec --- /dev/null +++ b/lib/data/provider/rate_data_provider.dart @@ -0,0 +1,181 @@ +import 'dart:async'; + +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:fcs/domain/constants.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; +import 'package:fcs/domain/entities/custom_duty.dart'; +import 'package:fcs/domain/entities/discount_by_weight.dart'; +import 'package:fcs/domain/entities/rate.dart'; +import 'package:fcs/helpers/api_helper.dart'; +import 'package:fcs/helpers/firebase_helper.dart'; +import 'package:logging/logging.dart'; + +class RateDataProvider { + final log = Logger('RateDataProvider'); + + static final RateDataProvider instance = RateDataProvider._(); + RateDataProvider._(); + + StreamController controller; + static Rate _rate = Rate(); + + Stream _rateStream() async* { + Stream snapshot = Firestore.instance + .collection(config_collection) + .document(rate_doc_id) + .snapshots(); + await for (var snap in snapshot) { + Rate rate = Rate.fromMap(snap.data); + yield rate; + } + } + + Stream> _cargoTypeStream() async* { + List cargoTypes = []; + Stream snapshots = Firestore.instance + .collection(config_collection) + .document(rate_doc_id) + .collection(cargo_types_collection) + .snapshots(); + + await for (var snaps in snapshots) { + cargoTypes = []; + cargoTypes = snaps.documents.map((snap) { + return CargoType.fromMap(snap.data, snap.documentID); + }).toList(); + + yield cargoTypes; + } + } + + Stream> _customDutiesStream() async* { + List customDuries = []; + Stream snapshots = Firestore.instance + .collection(config_collection) + .document(rate_doc_id) + .collection(custom_duties_collection) + .snapshots(); + + await for (var snaps in snapshots) { + customDuries = []; + customDuries = snaps.documents.map((snap) { + return CustomDuty.fromMap(snap.data, snap.documentID); + }).toList(); + yield customDuries; + } + } + + Stream> _discountByWeightStream() async* { + List discountByWeight = []; + Stream snapshots = Firestore.instance + .collection(config_collection) + .document(rate_doc_id) + .collection(discounts_by_weights_collection) + .snapshots(); + + await for (var snaps in snapshots) { + discountByWeight = []; + discountByWeight = snaps.documents.map((snap) { + return DiscountByWeight.fromMap(snap.data, snap.documentID); + }).toList(); + yield discountByWeight; + } + } + + StreamSubscription rateListener; + StreamSubscription> cargoListener; + StreamSubscription> customListener; + StreamSubscription> discountListener; + Stream rate() { + Future _start() async { + rateListener = _rateStream().listen((rate) { + _rate.deliveryFee = rate.deliveryFee; + _rate.freeDeliveryWeight = rate.freeDeliveryWeight; + _rate.volumetricRatio = rate.volumetricRatio; + controller.add(_rate); + }); + cargoListener = _cargoTypeStream().listen((cargoTypes) { + _rate.cargoTypes = cargoTypes; + controller.add(_rate); + }); + customListener = _customDutiesStream().listen((customDuties) { + _rate.customDuties = customDuties; + controller.add(_rate); + }); + discountListener = _discountByWeightStream().listen((discountByWeights) { + _rate.discountByWeights = discountByWeights; + controller.add(_rate); + }); + } + + void _stop() { + if (rateListener != null) { + rateListener.cancel(); + } + if (cargoListener != null) { + cargoListener.cancel(); + } + if (customListener != null) { + customListener.cancel(); + } + if (discountListener != null) { + discountListener.cancel(); + } + } + + controller = StreamController( + onListen: _start, onPause: _stop, onResume: _start, onCancel: _stop); + + return controller.stream; + } + + Future updateRates(Rate rate) async { + return await requestAPI("/rates", "PUT", + payload: rate.toMap(), token: await getToken()); + } + + Future createCargoType(CargoType cargoType) async { + return await requestAPI("/cargo_types", "POST", + payload: cargoType.toMap(), token: await getToken()); + } + + Future updateCargoType(CargoType cargoType) async { + return await requestAPI("/cargo_types", "PUT", + payload: cargoType.toMap(), token: await getToken()); + } + + Future deleteCargoType(String id) async { + return await requestAPI("/cargo_types", "DELETE", + payload: {"id": id}, token: await getToken()); + } + + Future createCustomDuty(CustomDuty customDuty) async { + return await requestAPI("/custom_duties", "POST", + payload: customDuty.toMap(), token: await getToken()); + } + + Future updateCustomDuty(CustomDuty customDuty) async { + return await requestAPI("/custom_duties", "PUT", + payload: customDuty.toMap(), token: await getToken()); + } + + Future deleteCustomDuty(String id) async { + return await requestAPI("/custom_duties", "PUT", + payload: {"id": id}, token: await getToken()); + } + + Future createDiscountByWeight(DiscountByWeight discountByWeight) async { + return await requestAPI("/discounts_by_weight", "POST", + payload: discountByWeight.toMap(), token: await getToken()); + } + + Future updateDiscountByWeight(DiscountByWeight discountByWeight) async { + return await requestAPI("/discounts_by_weight", "PUT", + payload: discountByWeight.toMap(), token: await getToken()); + } + + Future deleteDiscountByWeight(String id) async { + return await requestAPI("/discounts_by_weight", "PUT", + payload: {"id": id}, token: await getToken()); + } +} diff --git a/lib/data/services/rate_imp.dart b/lib/data/services/rate_imp.dart new file mode 100644 index 0000000..4f5c769 --- /dev/null +++ b/lib/data/services/rate_imp.dart @@ -0,0 +1,75 @@ +import 'package:fcs/data/provider/rate_data_provider.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; +import 'package:fcs/domain/entities/connectivity.dart'; +import 'package:fcs/domain/entities/discount_by_weight.dart'; +import 'package:fcs/domain/entities/custom_duty.dart'; +import 'package:fcs/domain/entities/rate.dart'; +import 'package:flutter/material.dart'; + +import 'rate_service.dart'; + +class RateServiceImp implements RateService { + RateServiceImp({ + @required this.rateDataProvider, + @required this.connectivity, + }); + + final Connectivity connectivity; + final RateDataProvider rateDataProvider; + + @override + Stream getRateStream() { + return rateDataProvider.rate(); + } + + @override + Future createCargoType(CargoType cargoType) { + return rateDataProvider.createCargoType(cargoType); + } + + @override + Future createCustomDuty(CustomDuty customDuty) { + return rateDataProvider.createCustomDuty(customDuty); + } + + @override + Future createDiscountByWeight(DiscountByWeight discountByWeight) { + return rateDataProvider.createDiscountByWeight(discountByWeight); + } + + @override + Future deleteCargoType(String id) { + return rateDataProvider.deleteCargoType(id); + } + + @override + Future deleteCustomDuty(String id) { + return rateDataProvider.deleteCustomDuty(id); + } + + @override + Future deleteDiscountByWeight(String id) { + return rateDataProvider.deleteDiscountByWeight(id); + } + + @override + Future updateCargoType(CargoType cargoType) { + return rateDataProvider.updateCargoType(cargoType); + } + + @override + Future updateCustomDuty(CustomDuty customDuty) { + return rateDataProvider.updateCustomDuty(customDuty); + } + + @override + Future updateDiscountByWeight(DiscountByWeight discountByWeight) { + return rateDataProvider.updateDiscountByWeight(discountByWeight); + } + + @override + Future updateRate(Rate rate) { + // TODO: implement updateRate + throw UnimplementedError(); + } +} diff --git a/lib/data/services/rate_service.dart b/lib/data/services/rate_service.dart new file mode 100644 index 0000000..98bf602 --- /dev/null +++ b/lib/data/services/rate_service.dart @@ -0,0 +1,22 @@ +import 'package:fcs/domain/entities/cargo_type.dart'; +import 'package:fcs/domain/entities/custom_duty.dart'; +import 'package:fcs/domain/entities/discount_by_weight.dart'; +import 'package:fcs/domain/entities/rate.dart'; + +abstract class RateService { + Stream getRateStream(); + + Future updateRate(Rate rate); + + Future createCargoType(CargoType cargoType); + Future updateCargoType(CargoType cargoType); + Future deleteCargoType(String id); + + Future createCustomDuty(CustomDuty customDuty); + Future updateCustomDuty(CustomDuty customDuty); + Future deleteCustomDuty(String id); + + Future createDiscountByWeight(DiscountByWeight discountByWeight); + Future updateDiscountByWeight(DiscountByWeight discountByWeight); + Future deleteDiscountByWeight(String id); +} diff --git a/lib/data/services/services.dart b/lib/data/services/services.dart index a42f0ee..7eb1d31 100644 --- a/lib/data/services/services.dart +++ b/lib/data/services/services.dart @@ -3,12 +3,14 @@ import 'package:fcs/data/provider/common_data_provider.dart'; import 'package:fcs/data/provider/delivery_address_data_provider.dart'; import 'package:fcs/data/provider/fcs_shipment_data_provider.dart'; import 'package:fcs/data/provider/package_data_provider.dart'; +import 'package:fcs/data/provider/rate_data_provider.dart'; import 'package:fcs/data/provider/user_data_provider.dart'; import 'package:fcs/data/services/delivery_address_imp.dart'; import 'package:fcs/data/services/delivery_address_service.dart'; import 'package:fcs/data/services/fcs_shipment_imp.dart'; import 'package:fcs/data/services/fcs_shipment_service.dart'; -import 'package:fcs/domain/vo/delivery_address.dart'; +import 'package:fcs/data/services/rate_imp.dart'; +import 'package:fcs/data/services/rate_service.dart'; import 'auth_imp.dart'; import 'auth_service.dart'; @@ -31,6 +33,7 @@ class Services { CommonService _commonService; FcsShipmentService _fcsShipmentService; DeliveryAddressService _deliveryAddressService; + RateService _rateService; Services._() { _authService = AuthServiceImp( authFb: AuthFb.instance, @@ -47,6 +50,8 @@ class Services { _deliveryAddressService = DeliveryAddressImp( connectivity: null, deliveryAddressDataProvider: DeliveryAddressDataProvider()); + _rateService = RateServiceImp( + rateDataProvider: RateDataProvider.instance, connectivity: null); } AuthService get authService => _authService; @@ -56,4 +61,5 @@ class Services { CommonService get commonService => _commonService; FcsShipmentService get fcsShipmentService => _fcsShipmentService; DeliveryAddressService get deliveryAddressService => _deliveryAddressService; + RateService get rateService => _rateService; } diff --git a/lib/data/services/shipment_service.dart b/lib/data/services/shipment_service.dart new file mode 100644 index 0000000..0a5f1ad --- /dev/null +++ b/lib/data/services/shipment_service.dart @@ -0,0 +1,23 @@ +import 'package:fcs/domain/entities/cargo_type.dart'; +import 'package:fcs/domain/entities/custom_duty.dart'; +import 'package:fcs/domain/entities/discount_by_weight.dart'; +import 'package:fcs/domain/entities/shipment.dart'; +import 'package:fcs/domain/entities/rate.dart'; + +abstract class RateService { + Stream getRateStream(); + + Future createShipment(Shipment shipment); + + Future createCargoType(CargoType cargoType); + Future updateCargoType(CargoType cargoType); + Future deleteCargoType(String id); + + Future createCustomDuty(CustomDuty customDuty); + Future updateCustomDuty(CustomDuty customDuty); + Future deleteCustomDuty(String id); + + Future createDiscountByWeight(DiscountByWeight discountByWeight); + Future updateDiscountByWeight(DiscountByWeight discountByWeight); + Future deleteDiscountByWeight(String id); +} diff --git a/lib/domain/constants.dart b/lib/domain/constants.dart index 88db0a9..99c7a36 100644 --- a/lib/domain/constants.dart +++ b/lib/domain/constants.dart @@ -1,13 +1,19 @@ const config_collection = "configs"; const user_collection = "users"; const invitations_collection = "invitations"; -const setting_doc_id = "setting"; const privilege_collection = "privileges"; const markets_collection = "markets"; const packages_collection = "packages"; const messages_collection = "messages"; const fcs_shipment_collection = "fcs_shipments"; const delivery_address_collection = "delivery_addresses"; +const cargo_types_collection = "cargo_types"; +const custom_duties_collection = "custom_duties"; +const discounts_by_weights_collection = "discounts_by_weight"; + +// docs +const setting_doc_id = "setting"; +const rate_doc_id = "rate"; const user_requested_status = "requested"; const user_invited_status = "invited"; @@ -17,6 +23,7 @@ const pkg_files_path = "/packages"; // Link page const page_payment_methods = "payment_methods"; const page_buying_instructions = "buying_instructions"; +const page_rates = "rates"; // Message type const message_type_package = "t_p"; diff --git a/lib/domain/entities/box.dart b/lib/domain/entities/box.dart index 51dae8b..43c0798 100644 --- a/lib/domain/entities/box.dart +++ b/lib/domain/entities/box.dart @@ -1,7 +1,7 @@ import 'package:fcs/domain/vo/shipment_status.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; -import 'cargo.dart'; +import 'cargo_type.dart'; import 'package.dart'; class Box { @@ -36,7 +36,7 @@ class Box { List packages; - List cargoTypes; + List cargoTypes; DeliveryAddress shippingAddress; diff --git a/lib/domain/entities/cargo.dart b/lib/domain/entities/cargo.dart deleted file mode 100644 index 746eee6..0000000 --- a/lib/domain/entities/cargo.dart +++ /dev/null @@ -1,17 +0,0 @@ -class Cargo { - String type; - int price; - int weight; - Cargo({this.type, this.price, this.weight}); - - @override - String toString() { - return type; - } - - @override - bool operator ==(Object other) => other is Cargo && other.type == type; - - @override - int get hashCode => type.hashCode; -} diff --git a/lib/domain/entities/cargo_type.dart b/lib/domain/entities/cargo_type.dart new file mode 100644 index 0000000..69e173f --- /dev/null +++ b/lib/domain/entities/cargo_type.dart @@ -0,0 +1,29 @@ +class CargoType { + String id; + String name; + double rate; + + factory CargoType.fromMap(Map map, String id) { + return CargoType( + id: id, + name: map['name'], + rate: (map['rate'] ?? 0).toDouble(), + ); + } + int weight; + CargoType({this.id, this.name, this.rate, this.weight}); + + Map toMap() { + return { + "id": id, + 'name': name, + 'rate': rate, + }; + } + + @override + bool operator ==(Object other) => other is CargoType && other.id == id; + + @override + int get hashCode => id.hashCode; +} diff --git a/lib/domain/entities/custom.dart b/lib/domain/entities/custom.dart deleted file mode 100644 index ed3273e..0000000 --- a/lib/domain/entities/custom.dart +++ /dev/null @@ -1,6 +0,0 @@ -class Custom{ - String id; - String productType; - int fee; - Custom({this.productType,this.fee}); -} \ No newline at end of file diff --git a/lib/domain/entities/custom_duty.dart b/lib/domain/entities/custom_duty.dart new file mode 100644 index 0000000..05b6daf --- /dev/null +++ b/lib/domain/entities/custom_duty.dart @@ -0,0 +1,25 @@ +class CustomDuty { + String id; + String productType; + String desc; + double fee; + CustomDuty({this.id, this.productType, this.desc, this.fee}); + + factory CustomDuty.fromMap(Map map, String id) { + return CustomDuty( + id: id, + productType: map['product_type'], + desc: map['desc'], + fee: (map['fee'] ?? 0).toDouble(), + ); + } + + Map toMap() { + return { + "id": id, + 'product_type': productType, + 'desc': desc, + 'fee': fee, + }; + } +} diff --git a/lib/domain/entities/discount_by_weight.dart b/lib/domain/entities/discount_by_weight.dart new file mode 100644 index 0000000..cc4b179 --- /dev/null +++ b/lib/domain/entities/discount_by_weight.dart @@ -0,0 +1,23 @@ +class DiscountByWeight { + String id; + double weight; + double discount; + + DiscountByWeight({this.id, this.weight, this.discount}); + + factory DiscountByWeight.fromMap(Map map, String id) { + return DiscountByWeight( + id: id, + weight: (map['weight'] ?? 0).toDouble(), + discount: (map['discount'] ?? 0).toDouble(), + ); + } + + Map toMap() { + return { + "id": id, + 'weight': weight, + 'discount': discount, + }; + } +} diff --git a/lib/domain/entities/discount_rate.dart b/lib/domain/entities/discount_rate.dart deleted file mode 100644 index 9d888fd..0000000 --- a/lib/domain/entities/discount_rate.dart +++ /dev/null @@ -1,6 +0,0 @@ -class DiscountRate { - int weight; - double discountRate; - - DiscountRate({this.weight, this.discountRate}); -} diff --git a/lib/domain/entities/rate.dart b/lib/domain/entities/rate.dart index c0faaf6..6410f88 100644 --- a/lib/domain/entities/rate.dart +++ b/lib/domain/entities/rate.dart @@ -1,31 +1,45 @@ +import 'package:fcs/domain/entities/custom_duty.dart'; +import 'package:fcs/domain/entities/discount_by_weight.dart'; + +import 'cargo_type.dart'; + class Rate { - String id; - String name; - String description; - String fromTime; - String toTime; - int price; + double deliveryFee; + double freeDeliveryWeight; + double volumetricRatio; - Rate( - {this.id, - this.name, - this.description, - this.fromTime, - this.toTime, - this.price,}); + List cargoTypes; + List customDuties; + List discountByWeights; - factory Rate.fromMap(Map map, String id) { + CargoType get defaultCargoType => cargoTypes == null + ? null + : cargoTypes.firstWhere((e) => e.name == "General"); + + Rate({ + this.deliveryFee, + this.freeDeliveryWeight, + this.volumetricRatio, + }); + + factory Rate.fromMap(Map map) { return Rate( - id: id, - name: map['name'], - description: map['description'], - fromTime: map['from_time'], - toTime: map['to_time'], - price: map['price'],); + deliveryFee: (map['delivery_fee'] ?? 0).toDouble(), + freeDeliveryWeight: (map['free_delivery_weight'] ?? 0).toDouble(), + volumetricRatio: (map['volumetric_ratio'] ?? 0).toDouble(), + ); + } + + Map toMap() { + return { + "delivery_fee": deliveryFee, + 'free_delivery_weight': freeDeliveryWeight, + 'volumetric_ratio': volumetricRatio, + }; } @override String toString() { - return 'Rate{id:$id, name:$name,description:$description,fromTime:$fromTime,toTime:$toTime}'; + return 'Rate{deliveryFee:$deliveryFee,freeDeliveryWeight:$freeDeliveryWeight,volumetricRatio:$volumetricRatio}'; } } diff --git a/lib/domain/entities/setting.dart b/lib/domain/entities/setting.dart index 242f5f8..8a203ee 100644 --- a/lib/domain/entities/setting.dart +++ b/lib/domain/entities/setting.dart @@ -1,6 +1,3 @@ -import 'package:fcs/domain/entities/cargo.dart'; -import 'package:fcs/domain/vo/delivery_address.dart'; - List dayLists = [ Day(id: 1, name: 'Sun'), Day(id: 2, name: 'Mon'), @@ -26,32 +23,24 @@ class Setting { final String termsEng; final String termsMm; String about; - double volumetricRatio; List shipmentTypes; - Map cargoTypes; - List get cargoTypesList => cargoTypes.entries - .map((e) => Cargo(type: e.key, price: e.value)) - .toList(); - Cargo get defaultCargoType => - cargoTypesList.firstWhere((e) => e.type == "General"); - Setting( - {this.supportBuildNum, - this.usaAddress, - this.mmAddress, - this.usaContactNumber, - this.mmContactNumber, - this.emailAddress, - this.facebookLink, - this.inviteRequired, - this.appUrl, - this.termsEng, - this.termsMm, - this.about, - this.shipmentTypes, - this.volumetricRatio, - this.cargoTypes}); + Setting({ + this.supportBuildNum, + this.usaAddress, + this.mmAddress, + this.usaContactNumber, + this.mmContactNumber, + this.emailAddress, + this.facebookLink, + this.inviteRequired, + this.appUrl, + this.termsEng, + this.termsMm, + this.about, + this.shipmentTypes, + }); factory Setting.fromMap(Map map) { return Setting( @@ -67,11 +56,7 @@ class Setting { about: map['about'], termsEng: map['terms_eng'], termsMm: map['terms_mm'], - volumetricRatio: map['volumetric_ratio'], shipmentTypes: List.from(map['shipment_types']), - cargoTypes: map['cargo_types'] == null - ? [] - : Map.from(map['cargo_types']), ); } diff --git a/lib/domain/entities/pickup.dart b/lib/domain/entities/shipment.dart similarity index 95% rename from lib/domain/entities/pickup.dart rename to lib/domain/entities/shipment.dart index 732b3f1..2c988dd 100644 --- a/lib/domain/entities/pickup.dart +++ b/lib/domain/entities/shipment.dart @@ -1,4 +1,4 @@ -import 'cargo.dart'; +import 'cargo_type.dart'; class Shipment { String id; @@ -12,7 +12,7 @@ class Shipment { String address; String status; DateTime date; - List cargoTypes; + List cargoTypes; bool isCourier; int radioIndex; diff --git a/lib/pages/box/box_editor.dart b/lib/pages/box/box_editor.dart index 022b40c..5dbd6a8 100644 --- a/lib/pages/box/box_editor.dart +++ b/lib/pages/box/box_editor.dart @@ -1,6 +1,6 @@ import 'package:fcs/domain/constants.dart'; import 'package:fcs/domain/entities/box.dart'; -import 'package:fcs/domain/entities/cargo.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/domain/entities/user.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; @@ -12,6 +12,7 @@ import 'package:fcs/pages/main/model/language_model.dart'; import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/package/model/package_model.dart'; +import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; import 'package:fcs/pages/user_search/user_serach.dart'; import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; import 'package:fcs/pages/widgets/defalut_delivery_address.dart'; @@ -54,7 +55,7 @@ class _BoxEditorState extends State { List _packages = []; List _shipmentBoxes = []; List _mixBoxes = []; - List _cargoTypes = []; + List _cargoTypes = []; double volumetricRatio = 0; double shipmentWeight = 0; Box _selectedShipmentBox; @@ -83,8 +84,9 @@ class _BoxEditorState extends State { }); //for shipment weight - volumetricRatio = - Provider.of(context, listen: false).setting.volumetricRatio; + volumetricRatio = Provider.of(context, listen: false) + .rate + .volumetricRatio; _lengthController.addListener(_calShipmentWeight); _widthController.addListener(_calShipmentWeight); _heightController.addListener(_calShipmentWeight); @@ -101,9 +103,9 @@ class _BoxEditorState extends State { isNew = false; } else { _cargoTypes = [ - Cargo(type: 'General', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous', weight: 30) + CargoType(id: "1", name: 'General', weight: 25), + CargoType(id: "2", name: 'Medicine', weight: 20), + CargoType(id: "3", name: 'Dangerous', weight: 30) ]; var shipmentModel = @@ -401,7 +403,7 @@ class _BoxEditorState extends State { total += c.value.weight; return InkWell( onTap: () async { - Cargo cargo = await Navigator.push( + CargoType cargo = await Navigator.push( context, CupertinoPageRoute( builder: (context) => CargoTypeEditor(cargo: c.value)), @@ -422,7 +424,7 @@ class _BoxEditorState extends State { children: [ Expanded( child: new Text( - c.value.type, + c.value.name, style: textStyle, )), Row( @@ -630,7 +632,7 @@ class _BoxEditorState extends State { color: primaryColor, ), onPressed: () async { - Cargo cargo = await Navigator.push( + CargoType cargo = await Navigator.push( context, CupertinoPageRoute( builder: (context) => CargoTypeEditor()), @@ -700,7 +702,7 @@ class _BoxEditorState extends State { }).toList(); } - _addCargo(Cargo cargo) { + _addCargo(CargoType cargo) { if (cargo == null) return; setState(() { _cargoTypes.remove(cargo); diff --git a/lib/pages/box/box_info.dart b/lib/pages/box/box_info.dart index c5442f5..770471f 100644 --- a/lib/pages/box/box_info.dart +++ b/lib/pages/box/box_info.dart @@ -1,12 +1,13 @@ import 'package:fcs/domain/constants.dart'; import 'package:fcs/domain/entities/box.dart'; -import 'package:fcs/domain/entities/cargo.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/package/model/package_model.dart'; +import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; import 'package:fcs/pages/widgets/defalut_delivery_address.dart'; import 'package:fcs/pages/widgets/display_text.dart'; @@ -48,7 +49,7 @@ class _BoxInfoState extends State { List _packages = []; List _mixBoxes = []; Box _selectedShipmentBox; - List _cargoTypes = []; + List _cargoTypes = []; DeliveryAddress _deliveryAddress = new DeliveryAddress(); TextEditingController _widthController = new TextEditingController(); TextEditingController _heightController = new TextEditingController(); @@ -83,8 +84,9 @@ class _BoxInfoState extends State { }); //for shipment weight - volumetricRatio = - Provider.of(context, listen: false).setting.volumetricRatio; + volumetricRatio = Provider.of(context, listen: false) + .rate + .volumetricRatio; _lengthController.addListener(_calShipmentWeight); _widthController.addListener(_calShipmentWeight); _heightController.addListener(_calShipmentWeight); @@ -342,7 +344,7 @@ class _BoxInfoState extends State { children: [ Expanded( child: new Text( - c.value.type, + c.value.name, style: textStyle, )), Container( diff --git a/lib/pages/box/cargo_type_editor.dart b/lib/pages/box/cargo_type_editor.dart index 2cba854..53e166f 100644 --- a/lib/pages/box/cargo_type_editor.dart +++ b/lib/pages/box/cargo_type_editor.dart @@ -1,7 +1,8 @@ -import 'package:fcs/domain/entities/cargo.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/main/model/main_model.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/local_dropdown.dart'; import 'package:fcs/pages/widgets/local_text.dart'; @@ -12,7 +13,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; class CargoTypeEditor extends StatefulWidget { - final Cargo cargo; + final CargoType cargo; CargoTypeEditor({this.cargo}); @override @@ -23,7 +24,7 @@ class _CargoTypeEditorState extends State { TextEditingController _weightController = new TextEditingController(); bool _isLoading = false; - Cargo _cargo; + CargoType _cargo; @override void initState() { @@ -37,8 +38,9 @@ class _CargoTypeEditorState extends State { } _loadDefalut() { - MainModel mainModel = Provider.of(context, listen: false); - _cargo = mainModel.setting.defaultCargoType; + ShipmentRateModel shipmentRateModel = + Provider.of(context, listen: false); + _cargo = shipmentRateModel.rate.defaultCargoType; } @override @@ -48,8 +50,9 @@ class _CargoTypeEditorState extends State { @override Widget build(BuildContext context) { - MainModel mainModel = Provider.of(context); - List cargos = mainModel.setting.cargoTypesList; + ShipmentRateModel shipmentRateModel = + Provider.of(context); + List cargos = shipmentRateModel.rate.cargoTypes; final rateBox = InputText( labelTextKey: 'cargo.weight', @@ -57,7 +60,7 @@ class _CargoTypeEditorState extends State { textInputType: TextInputType.number, controller: _weightController); - var cargoTypeBox = LocalDropdown( + var cargoTypeBox = LocalDropdown( callback: (v) { setState(() { _cargo = v; diff --git a/lib/pages/box/model/box_model.dart b/lib/pages/box/model/box_model.dart index 41ba64c..77f4014 100644 --- a/lib/pages/box/model/box_model.dart +++ b/lib/pages/box/model/box_model.dart @@ -3,7 +3,7 @@ import 'dart:async'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:fcs/domain/constants.dart'; import 'package:fcs/domain/entities/box.dart'; -import 'package:fcs/domain/entities/cargo.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/domain/vo/shipment_status.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; @@ -55,9 +55,9 @@ class BoxModel extends BaseModel { state: 'NY', phoneNumber: '+1 (292)215-2247'), cargoTypes: [ - Cargo(type: 'General', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous', weight: 30) + CargoType(name: 'General', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous', weight: 30) ]), Box( shipmentNumber: "A203", @@ -87,9 +87,9 @@ class BoxModel extends BaseModel { state: 'Myanmar', phoneNumber: '+09 95724 8750'), cargoTypes: [ - Cargo(type: 'General', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous', weight: 30) + CargoType(name: 'General', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous', weight: 30) ]), Box( shipmentNumber: "A204", @@ -119,9 +119,9 @@ class BoxModel extends BaseModel { state: 'Myanmar', phoneNumber: '+09 95724 8750'), cargoTypes: [ - Cargo(type: 'General', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous', weight: 30) + CargoType(name: 'General', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous', weight: 30) ]), Box( shipmentNumber: "A202", @@ -150,9 +150,9 @@ class BoxModel extends BaseModel { state: 'NY', phoneNumber: '+1 (292)215-2247'), cargoTypes: [ - Cargo(type: 'General', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous', weight: 30) + CargoType(name: 'General', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous', weight: 30) ]), Box( shipmentNumber: "A202", @@ -180,9 +180,9 @@ class BoxModel extends BaseModel { state: 'NY', phoneNumber: '+1 (292)215-2247'), cargoTypes: [ - Cargo(type: 'General', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous', weight: 30) + CargoType(name: 'General', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous', weight: 30) ]), Box( shipmentNumber: "A202", @@ -210,9 +210,9 @@ class BoxModel extends BaseModel { state: 'NY', phoneNumber: '+1 (292)215-2247'), cargoTypes: [ - Cargo(type: 'General', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous', weight: 30) + CargoType(name: 'General', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous', weight: 30) ]), Box( shipmentNumber: "A201", @@ -240,9 +240,9 @@ class BoxModel extends BaseModel { state: 'NY', phoneNumber: '+1 (292)215-2247'), cargoTypes: [ - Cargo(type: 'General', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous', weight: 30) + CargoType(name: 'General', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous', weight: 30) ]), Box( shipmentNumber: "A201", @@ -270,9 +270,9 @@ class BoxModel extends BaseModel { state: 'NY', phoneNumber: '+1 (292)215-2247'), cargoTypes: [ - Cargo(type: 'General', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous', weight: 30) + CargoType(name: 'General', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous', weight: 30) ]), ]; diff --git a/lib/pages/delivery_address/delivery_address_editor.dart b/lib/pages/delivery_address/delivery_address_editor.dart index 234671b..cda652b 100644 --- a/lib/pages/delivery_address/delivery_address_editor.dart +++ b/lib/pages/delivery_address/delivery_address_editor.dart @@ -105,16 +105,13 @@ class _DeliveryAddressEditorState extends State { appBar: AppBar( centerTitle: true, leading: new IconButton( - icon: new Icon(CupertinoIcons.back), + icon: new Icon(CupertinoIcons.back, color: primaryColor), onPressed: () => Navigator.of(context).pop(), ), - backgroundColor: primaryColor, - title: LocalText( - context, - 'delivery_address', - color: Colors.white, - fontSize: 20, - ), + backgroundColor: Colors.white, + shadowColor: Colors.transparent, + title: LocalText(context, 'delivery_address', + color: primaryColor, fontSize: 18), actions: [IconButton(icon: Icon(Icons.delete), onPressed: _delete)], ), body: Padding( diff --git a/lib/pages/delivery_address/delivery_address_list.dart b/lib/pages/delivery_address/delivery_address_list.dart index 7684067..b096bef 100644 --- a/lib/pages/delivery_address/delivery_address_list.dart +++ b/lib/pages/delivery_address/delivery_address_list.dart @@ -2,15 +2,14 @@ import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/delivery_address/delivery_address_editor.dart'; import 'package:fcs/pages/main/util.dart'; -import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'model/delivery_address_model.dart'; import 'delivery_address_row.dart'; +import 'model/delivery_address_model.dart'; class DeliveryAddressList extends StatefulWidget { const DeliveryAddressList({Key key}) : super(key: key); @@ -41,16 +40,13 @@ class _DeliveryAddressListState extends State { appBar: AppBar( centerTitle: true, leading: new IconButton( - icon: new Icon(CupertinoIcons.back), - onPressed: () => Navigator.pop(context), - ), - backgroundColor: primaryColor, - title: LocalText( - context, - "delivery_addresses", - fontSize: 20, - color: Colors.white, + icon: new Icon(CupertinoIcons.back, color: primaryColor), + onPressed: () => Navigator.of(context).pop(), ), + backgroundColor: Colors.white, + shadowColor: Colors.transparent, + title: LocalText(context, 'delivery_addresses', + color: primaryColor, fontSize: 20), ), floatingActionButton: FloatingActionButton.extended( onPressed: () { diff --git a/lib/pages/faq/faq_edit_page.dart b/lib/pages/faq/faq_edit_page.dart index 524a7d5..b43d7ff 100644 --- a/lib/pages/faq/faq_edit_page.dart +++ b/lib/pages/faq/faq_edit_page.dart @@ -94,8 +94,12 @@ class _FAQEditorState extends State { _pageLink = newValue; }); }, - items: [info, page_buying_instructions, page_payment_methods] - .map>((String value) { + items: [ + info, + page_buying_instructions, + page_payment_methods, + page_rates + ].map>((String value) { return DropdownMenuItem( value: value, child: Text( @@ -116,6 +120,64 @@ class _FAQEditorState extends State { ); return LocalProgress( + inAsyncCall: _isLoading, + child: Scaffold( + appBar: AppBar( + centerTitle: true, + leading: new IconButton( + icon: new Icon(CupertinoIcons.back, color: primaryColor), + onPressed: () => Navigator.of(context).pop(), + ), + backgroundColor: Colors.white, + shadowColor: Colors.transparent, + title: LocalText( + context, _isNew ? 'faq.add.title' : 'faq.edit.title', + color: primaryColor, fontSize: 20), + actions: [ + IconButton( + icon: Icon(Icons.delete), + onPressed: _delete, + ) + ], + ), + body: Form( + key: _formKey, + child: Padding( + padding: EdgeInsets.only(left: 24.0, right: 24.0), + child: ListView( + children: [ + snBox, + Center(child: itemTitle(context, "faq.edit.eng")), + subItemTitle(context, "faq.edit.question", + iconData: SimpleLineIcons.question), + questionEngBox, + subItemTitle(context, "faq.edit.answer", + iconData: MaterialCommunityIcons.message_reply_text), + answerEngBox, + Divider(), + Center(child: itemTitle(context, "faq.edit.mm")), + subItemTitle(context, "faq.edit.question", + iconData: SimpleLineIcons.question), + questionMmBox, + subItemTitle(context, "faq.edit.answer", + iconData: MaterialCommunityIcons.message_reply_text), + answerMmBox, + Divider(), + Center(child: itemTitle(context, "faq.edit.page")), + pageLinkBox, + pageLabelEngBox, + pageLabelMmBox, + fcsButton(context, getLocalString(context, "btn.save"), + callack: _save), + SizedBox( + height: 20, + ) + ], + ), + ), + ))); + + LocalProgress( inAsyncCall: _isLoading, child: Scaffold( body: CustomScrollView(slivers: [ diff --git a/lib/pages/faq/faq_list_page.dart b/lib/pages/faq/faq_list_page.dart index a515677..7d0f625 100644 --- a/lib/pages/faq/faq_list_page.dart +++ b/lib/pages/faq/faq_list_page.dart @@ -7,6 +7,7 @@ import 'package:fcs/pages/faq/faq_edit_page.dart'; import 'package:fcs/pages/main/model/language_model.dart'; import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/payment_methods/payment_method_page.dart'; +import 'package:fcs/pages/rates/shipment_rates.dart'; import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; import 'package:fcs/pages/widgets/fcs_expansion_tile.dart'; import 'package:fcs/pages/widgets/local_text.dart'; @@ -43,6 +44,32 @@ class _FAQListPageState extends State bool isEditable = context.select((MainModel m) => m.faqEditable()); return Scaffold( + appBar: AppBar( + centerTitle: true, + title: LocalText( + context, + "faq.title", + color: Colors.white, + fontSize: 20, + ), + leading: new IconButton( + icon: new Icon(CupertinoIcons.back), + onPressed: () => Navigator.of(context).pop(), + ), + backgroundColor: primaryColor, + actions: isEditable + ? [ + IconButton( + onPressed: () => setState(() { + isEditMode = !isEditMode; + }), + icon: Icon( + Icons.edit, + color: Colors.white, + )) + ] + : [], + ), floatingActionButton: isEditable ? FloatingActionButton.extended( onPressed: () { @@ -54,54 +81,11 @@ class _FAQListPageState extends State backgroundColor: primaryColor, ) : Container(), - body: CustomScrollView( - slivers: [ - SliverAppBar( - leading: IconButton( - icon: Icon( - CupertinoIcons.back, - size: 30, - ), - onPressed: () => Navigator.of(context).pop(), - ), - backgroundColor: primaryColor, - expandedHeight: 150.0, - floating: false, - pinned: true, - flexibleSpace: FlexibleSpaceBar( - centerTitle: true, - titlePadding: - EdgeInsets.symmetric(vertical: 10, horizontal: 45), - title: LocalText( - context, - "faq.title", - fontSize: 20, - color: Colors.white, - ), - ), - actions: isEditable - ? [ - IconButton( - onPressed: () => setState(() { - isEditMode = !isEditMode; - }), - icon: Icon( - Icons.edit, - color: Colors.white, - )) - ] - : [], - ), - SliverList( - delegate: SliverChildBuilderDelegate( - (context, index) { - return _faqItem(context, faqModel.faqs[index]); - }, - childCount: faqModel.faqs.length, - ), - ) - ], - )); + body: ListView.builder( + itemCount: faqModel.faqs.length, + itemBuilder: (BuildContext context, int index) { + return _faqItem(context, faqModel.faqs[index]); + })); } bool isEditMode = false; @@ -177,6 +161,9 @@ class _FAQListPageState extends State } else if (linkPage == page_buying_instructions) { Navigator.of(context) .push(CupertinoPageRoute(builder: (context) => BuyingOnlinePage())); + } else if (linkPage == page_rates) { + Navigator.of(context) + .push(CupertinoPageRoute(builder: (context) => ShipmentRates())); } } } diff --git a/lib/pages/invoice/invoice_editor.dart b/lib/pages/invoice/invoice_editor.dart index eea50b8..f0178d6 100644 --- a/lib/pages/invoice/invoice_editor.dart +++ b/lib/pages/invoice/invoice_editor.dart @@ -1,6 +1,6 @@ import 'package:fcs/domain/entities/box.dart'; -import 'package:fcs/domain/entities/cargo.dart'; -import 'package:fcs/domain/entities/custom.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; +import 'package:fcs/domain/entities/custom_duty.dart'; import 'package:fcs/domain/entities/discount.dart'; import 'package:fcs/domain/entities/invoice.dart'; import 'package:fcs/domain/entities/payment_method.dart'; @@ -14,6 +14,7 @@ import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/payment_methods/model/payment_method_model.dart'; import 'package:fcs/pages/rates/custom_list.dart'; +import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; import 'package:fcs/pages/user_search/user_serach.dart'; import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; import 'package:fcs/pages/widgets/discount_dropdown.dart'; @@ -67,7 +68,7 @@ class _InvoiceEditorState extends State { List _boxes = []; bool isSwitched = false; int deliveryfee = 0; - int customFee = 10; + double customFee = 10; int handlingFee = 0; double total = 0; Discount _discount; @@ -78,12 +79,12 @@ class _InvoiceEditorState extends State { double volumetricRatio = 0; List selectedBoxes = []; - List customs = []; + List customs = []; - List _cargoTypes = [ - Cargo(type: 'General Cargo', weight: 33, price: 6), - Cargo(type: 'Medicine', weight: 33, price: 7), - Cargo(type: 'Dangerous Cargo', weight: 33, price: 8) + List _cargoTypes = [ + CargoType(name: 'General Cargo', weight: 33, rate: 6), + CargoType(name: 'Medicine', weight: 33, rate: 7), + CargoType(name: 'Dangerous Cargo', weight: 33, rate: 8) ]; List _receipts = [ @@ -94,8 +95,9 @@ class _InvoiceEditorState extends State { void initState() { super.initState(); - volumetricRatio = - Provider.of(context, listen: false).setting.volumetricRatio; + volumetricRatio = Provider.of(context, listen: false) + .rate + .volumetricRatio; if (widget.invoice != null) { _invoice = widget.invoice; @@ -148,9 +150,9 @@ class _InvoiceEditorState extends State { // packages: packages, // statusHistory: statusHistory, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Box( shipmentNumber: "A202", @@ -170,9 +172,9 @@ class _InvoiceEditorState extends State { // packages: packages, receiverAddress: '1 Bo Yar Nyunt St.\nDagon Tsp, Yangon', cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]) ]; } @@ -257,7 +259,7 @@ class _InvoiceEditorState extends State { trailing: IconButton( icon: Icon(Icons.add_circle, color: primaryColor), onPressed: () async { - Custom custom = await Navigator.of(context).push( + CustomDuty custom = await Navigator.of(context).push( CupertinoPageRoute( builder: (context) => CustomList())); setState(() { @@ -492,7 +494,7 @@ class _InvoiceEditorState extends State { var discountModel = Provider.of(context); total = 0; List dataRow = _cargoTypes.map((cargo) { - var amount = cargo.weight * cargo.price; + var amount = cargo.weight * cargo.rate; total += amount; return Container( decoration: BoxDecoration( @@ -501,10 +503,10 @@ class _InvoiceEditorState extends State { left: 5.0, right: 5.0, top: 15.0, bottom: 15.0), child: Row( children: [ - Expanded(flex: 2, child: Text('${cargo.type}')), + Expanded(flex: 2, child: Text('${cargo.name}')), Expanded( flex: 2, - child: Text('${cargo.weight} x ${cargo.price}', + child: Text('${cargo.weight} x ${cargo.rate}', textAlign: TextAlign.center)), Expanded( child: Text('\$ $amount', @@ -820,7 +822,7 @@ class _InvoiceEditorState extends State { return _boxes.map((p) { p.cargoTypes.map((cargo) { _cargoTypes.asMap().map((index, _cargo) { - if (_cargo.type == cargo.type) { + if (_cargo.id == cargo.id) { setState(() { _cargoTypes[index].weight += cargo.weight; }); @@ -860,16 +862,16 @@ class _InvoiceEditorState extends State { List getCargoDataRow(BuildContext context) { return _cargoTypes.asMap().entries.map((c) { var cargo = c.value; - var amt = cargo.weight * cargo.price; + var amt = cargo.weight * cargo.rate; return MyDataRow( onSelectChanged: (bool selected) {}, cells: [ MyDataCell(new Text( - cargo.type, + cargo.name, style: textStyle, )), MyDataCell(new Text( - cargo.weight.toString() + ' x ' + cargo.price.toString(), + cargo.weight.toString() + ' x ' + cargo.rate.toString(), style: textStyle, )), MyDataCell(new Text( diff --git a/lib/pages/invoice/invoice_info.dart b/lib/pages/invoice/invoice_info.dart index 6d243ab..1c73e36 100644 --- a/lib/pages/invoice/invoice_info.dart +++ b/lib/pages/invoice/invoice_info.dart @@ -1,6 +1,6 @@ import 'package:fcs/domain/entities/box.dart'; -import 'package:fcs/domain/entities/cargo.dart'; -import 'package:fcs/domain/entities/custom.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; +import 'package:fcs/domain/entities/custom_duty.dart'; import 'package:fcs/domain/entities/discount.dart'; import 'package:fcs/domain/entities/invoice.dart'; import 'package:fcs/domain/entities/payment_method.dart'; @@ -15,6 +15,7 @@ import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/payment_methods/model/payment_method_model.dart'; import 'package:fcs/pages/rates/custom_list.dart'; +import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; import 'package:fcs/pages/user_search/user_serach.dart'; import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; import 'package:fcs/pages/widgets/discount_dropdown.dart'; @@ -67,7 +68,7 @@ class _InvoiceInfoPageState extends State { List _boxes = []; bool isSwitched = false; int deliveryfee = 0; - int customFee = 0; + double customFee = 0; double total = 0; Discount _discount; bool isNew = false; @@ -77,12 +78,12 @@ class _InvoiceInfoPageState extends State { double volumetricRatio = 0; List selectedBoxes = []; - List customs = []; + List customs = []; - List _cargoTypes = [ - Cargo(type: 'General Cargo', weight: 33, price: 6), - Cargo(type: 'Medicine', weight: 33, price: 7), - Cargo(type: 'Dangerous Cargo', weight: 33, price: 8) + List _cargoTypes = [ + CargoType(id: "1", name: 'General Cargo', weight: 33, rate: 6), + CargoType(id: "2", name: 'Medicine', weight: 33, rate: 7), + CargoType(id: "3", name: 'Dangerous Cargo', weight: 33, rate: 8) ]; List _receipts = [ @@ -92,8 +93,9 @@ class _InvoiceInfoPageState extends State { @override void initState() { super.initState(); - volumetricRatio = - Provider.of(context, listen: false).setting.volumetricRatio; + volumetricRatio = Provider.of(context, listen: false) + .rate + .volumetricRatio; if (widget.invoice != null) { _invoice = widget.invoice; @@ -142,9 +144,9 @@ class _InvoiceInfoPageState extends State { // packages: packages, // statusHistory: statusHistory, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Box( shipmentNumber: "A202", @@ -164,9 +166,9 @@ class _InvoiceInfoPageState extends State { // packages: packages, receiverAddress: '1 Bo Yar Nyunt St.\nDagon Tsp, Yangon', cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]) ]; } @@ -444,7 +446,7 @@ class _InvoiceInfoPageState extends State { getCargoTableByBox(BuildContext context) { total = 0; List dataRow = _cargoTypes.map((cargo) { - var amount = cargo.weight * cargo.price; + var amount = cargo.weight * cargo.rate; total += amount; return Container( decoration: BoxDecoration( @@ -453,10 +455,10 @@ class _InvoiceInfoPageState extends State { left: 5.0, right: 5.0, top: 15.0, bottom: 15.0), child: Row( children: [ - Expanded(flex: 2, child: Text('${cargo.type}')), + Expanded(flex: 2, child: Text('${cargo.rate}')), Expanded( flex: 2, - child: Text('${cargo.weight} x ${cargo.price}', + child: Text('${cargo.weight} x ${cargo.rate}', textAlign: TextAlign.center)), Expanded( child: Text('\$ $amount', @@ -736,7 +738,7 @@ class _InvoiceInfoPageState extends State { return _boxes.map((p) { p.cargoTypes.map((cargo) { _cargoTypes.asMap().map((index, _cargo) { - if (_cargo.type == cargo.type) { + if (_cargo.id == cargo.id) { setState(() { _cargoTypes[index].weight += cargo.weight; }); @@ -776,16 +778,16 @@ class _InvoiceInfoPageState extends State { List getCargoDataRow(BuildContext context) { return _cargoTypes.asMap().entries.map((c) { var cargo = c.value; - var amt = cargo.weight * cargo.price; + var amt = cargo.weight * cargo.rate; return MyDataRow( onSelectChanged: (bool selected) {}, cells: [ MyDataCell(new Text( - cargo.type, + cargo.name, style: textStyle, )), MyDataCell(new Text( - cargo.weight.toString() + ' x ' + cargo.price.toString(), + cargo.weight.toString() + ' x ' + cargo.rate.toString(), style: textStyle, )), MyDataCell(new Text( diff --git a/lib/pages/invoice/invoice_shipment_list_row.dart b/lib/pages/invoice/invoice_shipment_list_row.dart index 1ff356b..a5d0eb9 100644 --- a/lib/pages/invoice/invoice_shipment_list_row.dart +++ b/lib/pages/invoice/invoice_shipment_list_row.dart @@ -1,4 +1,4 @@ -import 'package:fcs/domain/entities/pickup.dart'; +import 'package:fcs/domain/entities/shipment.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; diff --git a/lib/pages/main/home_page.dart b/lib/pages/main/home_page.dart index 33b4c32..21389b6 100644 --- a/lib/pages/main/home_page.dart +++ b/lib/pages/main/home_page.dart @@ -24,12 +24,10 @@ import 'package:fcs/pages/package/model/package_model.dart'; import 'package:fcs/pages/package/package_info.dart'; import 'package:fcs/pages/package/package_list.dart'; import 'package:fcs/pages/processing/processing_list.dart'; -import 'package:fcs/pages/rates/shipment_rates.dart'; import 'package:fcs/pages/receiving/receiving_list.dart'; import 'package:fcs/pages/shipment/shipment_list.dart'; import 'package:fcs/pages/staff/staff_list.dart'; import 'package:fcs/pages/widgets/badge.dart'; -import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; import 'package:fcs/pages/widgets/bottom_widgets.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/progress.dart'; @@ -254,12 +252,6 @@ class _HomePageState extends State { btnCallback: () => Navigator.of(context) .push(CupertinoPageRoute(builder: (context) => ShipmentList()))); - final shipmentCostBtn = TaskButton("rate", - icon: FontAwesomeIcons.calculator, - btnCallback: () => Navigator.of(context).push(CupertinoPageRoute( - builder: (context) => ShipmentRates(), - ))); - final fcsShipmentBtn = TaskButton("FCSshipment.title", icon: Ionicons.ios_airplane, btnCallback: () => Navigator.of(context).push(CupertinoPageRoute( @@ -324,7 +316,6 @@ class _HomePageState extends State { widgets.add(shipmentBtn); widgets.add(invoicesBtn); widgets.add(faqBtn); - widgets.add(shipmentCostBtn); List widgetsFcs = []; if (user.hasPackages()) widgetsFcs.add(packagesBtnFcs); @@ -374,7 +365,8 @@ class _HomePageState extends State { ); final signinBtn = FlatButton( onPressed: () { - Navigator.of(context).push(CupertinoPageRoute(builder: (context) => SigninPage())); + Navigator.of(context) + .push(CupertinoPageRoute(builder: (context) => SigninPage())); }, child: Text( "Sign In", diff --git a/lib/pages/main/model/main_model.dart b/lib/pages/main/model/main_model.dart index 14a7846..866b13c 100644 --- a/lib/pages/main/model/main_model.dart +++ b/lib/pages/main/model/main_model.dart @@ -45,6 +45,10 @@ class MainModel extends ChangeNotifier { return this.user != null && this.user.hasSupport(); } + bool rateEditable() { + return this.user != null && this.user.hasSupport(); + } + bool paymentMethodsEditable() { return this.user != null && this.user.hasSupport(); } diff --git a/lib/pages/package/package_info.dart b/lib/pages/package/package_info.dart index 54bde2b..2857d18 100644 --- a/lib/pages/package/package_info.dart +++ b/lib/pages/package/package_info.dart @@ -5,7 +5,6 @@ import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart'; import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/package/model/package_model.dart'; -import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; import 'package:fcs/pages/widgets/defalut_delivery_address.dart'; import 'package:fcs/pages/widgets/delivery_address_selection.dart'; import 'package:fcs/pages/widgets/display_text.dart'; @@ -20,7 +19,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_icons/flutter_icons.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; -import 'package:timeline_list/timeline_model.dart'; final DateFormat dateFormat = DateFormat("d MMM yyyy"); @@ -84,11 +82,6 @@ class _PackageInfoState extends State { labelTextKey: "package.create.name", iconData: Icons.perm_identity, ); - final statusBox = DisplayText( - text: _package.currentStatus, - labelTextKey: "package.edit.status", - iconData: AntDesign.exclamationcircleo, - ); final marketBox = DisplayText( text: _package.market ?? "-", labelTextKey: "package.create.market", @@ -156,7 +149,6 @@ class _PackageInfoState extends State { widget.isSearchResult ? Container() : fcsIDBox, widget.isSearchResult ? Container() : customerNameBox, widget.isSearchResult ? Container() : marketBox, - statusBox, _package.photoUrls.length == 0 ? Container() : img, widget.isSearchResult ? Container() : descBox, remarkBox, diff --git a/lib/pages/rates/cargo_editor.dart b/lib/pages/rates/cargo_editor.dart index b100f59..a9b93ed 100644 --- a/lib/pages/rates/cargo_editor.dart +++ b/lib/pages/rates/cargo_editor.dart @@ -1,4 +1,4 @@ -import 'package:fcs/domain/entities/rate.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/localization/app_translations.dart'; import 'package:fcs/pages/main/util.dart'; @@ -8,8 +8,8 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class CargoEditor extends StatefulWidget { - final Rate rate; - CargoEditor({this.rate}); + final CargoType cargo; + CargoEditor({this.cargo}); @override _CargoEditorState createState() => _CargoEditorState(); @@ -20,15 +20,14 @@ class _CargoEditorState extends State { TextEditingController _rateController = new TextEditingController(); bool _isLoading = false; - Rate _rate = new Rate(); - + CargoType _cargo; @override void initState() { super.initState(); - if (widget.rate != null) { - _rate = widget.rate; - _descController.text = _rate.description; - _rateController.text = _rate.price.toString(); + if (widget.cargo != null) { + _cargo = widget.cargo; + _descController.text = _cargo.name; + _rateController.text = _cargo.rate.toString(); } } @@ -72,7 +71,7 @@ class _CargoEditorState extends State { ], ), ), - widget.rate == null + widget.cargo == null ? fcsButton(context, "Create", callack: () {}) : fcsButton(context, "Save", callack: () {}), SizedBox(height: 10) diff --git a/lib/pages/rates/custom_editor.dart b/lib/pages/rates/custom_editor.dart index afeb965..a8cd494 100644 --- a/lib/pages/rates/custom_editor.dart +++ b/lib/pages/rates/custom_editor.dart @@ -1,4 +1,4 @@ -import 'package:fcs/domain/entities/custom.dart'; +import 'package:fcs/domain/entities/custom_duty.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/localization/app_translations.dart'; import 'package:fcs/pages/main/util.dart'; @@ -9,7 +9,7 @@ import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; class CustomEditor extends StatefulWidget { - final Custom custom; + final CustomDuty custom; CustomEditor({this.custom}); @override @@ -21,7 +21,7 @@ class _CustomEditorState extends State { TextEditingController _feeController = new TextEditingController(); bool _isLoading = false; - Custom _custom = new Custom(); + CustomDuty _custom = new CustomDuty(); @override void initState() { diff --git a/lib/pages/rates/custom_list.dart b/lib/pages/rates/custom_list.dart index 7907352..b2f399c 100644 --- a/lib/pages/rates/custom_list.dart +++ b/lib/pages/rates/custom_list.dart @@ -1,4 +1,4 @@ -import 'package:fcs/domain/entities/custom.dart'; +import 'package:fcs/domain/entities/custom_duty.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/delivery_address/delivery_address_editor.dart'; @@ -60,17 +60,18 @@ class _CustomListState extends State { separatorBuilder: (c, i) => Divider( color: primaryColor, ), - itemCount: shipmentRateModel.customs.length, + itemCount: shipmentRateModel.rate.customDuties.length, itemBuilder: (context, index) { - return _row(context, shipmentRateModel.customs[index]); + return _row( + context, shipmentRateModel.rate.customDuties[index]); }), )), ); } - _row(BuildContext context, Custom custom) { + _row(BuildContext context, CustomDuty custom) { return InkWell( - onTap: () => Navigator.pop(context, custom), + onTap: () => Navigator.pop(context, custom), child: Row( children: [ Expanded( diff --git a/lib/pages/rates/custom_row.dart b/lib/pages/rates/custom_row.dart index c3602b7..87a1a89 100644 --- a/lib/pages/rates/custom_row.dart +++ b/lib/pages/rates/custom_row.dart @@ -1,4 +1,4 @@ -import 'package:fcs/domain/entities/custom.dart'; +import 'package:fcs/domain/entities/custom_duty.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/widgets/local_text.dart'; @@ -6,13 +6,12 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_icons/flutter_icons.dart'; -typedef SelectionCallback(Custom custom); +typedef SelectionCallback(CustomDuty custom); class CustomRow extends StatelessWidget { - final Custom custom; + final CustomDuty custom; final SelectionCallback selectionCallback; - const CustomRow( - {Key key, this.custom, this.selectionCallback}) + const CustomRow({Key key, this.custom, this.selectionCallback}) : super(key: key); @override @@ -33,7 +32,6 @@ class CustomRow extends StatelessWidget { fontSize: 16), line(context, custom.fee.toString(), iconData: Icons.phone, color: primaryColor, fontSize: 16), - ], ), ), diff --git a/lib/pages/rates/model/shipment_rate_model.dart b/lib/pages/rates/model/shipment_rate_model.dart index f1f25c4..a8ea478 100644 --- a/lib/pages/rates/model/shipment_rate_model.dart +++ b/lib/pages/rates/model/shipment_rate_model.dart @@ -1,8 +1,6 @@ import 'dart:async'; -import 'package:cloud_firestore/cloud_firestore.dart'; -import 'package:fcs/domain/entities/custom.dart'; -import 'package:fcs/domain/entities/discount_rate.dart'; +import 'package:fcs/data/services/services.dart'; import 'package:fcs/domain/entities/rate.dart'; import 'package:fcs/pages/main/model/base_model.dart'; import 'package:logging/logging.dart'; @@ -10,38 +8,20 @@ import 'package:logging/logging.dart'; class ShipmentRateModel extends BaseModel { final log = Logger('ShipmentRateModel'); - StreamSubscription listener; - - List rates = [ - Rate( - id: '1', name: 'general_cargo', description: 'General Cargo', price: 6), - Rate(id: '2', name: 'medicine', description: 'Medicine', price: 7), - Rate( - id: '3', - name: 'dangerous_cargo', - description: 'Dangerous Cargo', - price: 8), - ]; - - List customs = [ - Custom(productType: 'Phone', fee: 40), - Custom(productType: 'Max Book', fee: 40) - ]; - - List discountsByWeight = [ - DiscountRate(weight: 50, discountRate: 0.25), - DiscountRate(weight: 100, discountRate: 0.50) - ]; - - int freeDeliveryWeight = 10; + StreamSubscription listener; + Rate rate; void initUser(user) { super.initUser(user); + if (listener != null) listener.cancel(); + listener = Services.instance.rateService.getRateStream().listen((rate) { + this.rate = rate; + notifyListeners(); + }); } @override logout() async { if (listener != null) await listener.cancel(); - rates = []; } } diff --git a/lib/pages/rates/shipment_rates.dart b/lib/pages/rates/shipment_rates.dart index b562e4a..95aeff5 100644 --- a/lib/pages/rates/shipment_rates.dart +++ b/lib/pages/rates/shipment_rates.dart @@ -1,8 +1,10 @@ -import 'package:fcs/domain/entities/custom.dart'; -import 'package:fcs/domain/entities/discount_rate.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; +import 'package:fcs/domain/entities/custom_duty.dart'; +import 'package:fcs/domain/entities/discount_by_weight.dart'; import 'package:fcs/domain/entities/rate.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/localization/app_translations.dart'; +import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; import 'package:fcs/pages/widgets/local_text.dart'; @@ -38,6 +40,8 @@ class _ShipmentRatesState extends State { @override Widget build(BuildContext context) { var shipmentRateModel = Provider.of(context); + Rate rate = shipmentRateModel.rate; + bool isEditable = context.select((MainModel m) => m.rateEditable()); return LocalProgress( inAsyncCall: _isLoading, @@ -45,22 +49,38 @@ class _ShipmentRatesState extends State { appBar: AppBar( centerTitle: true, leading: new IconButton( - icon: new Icon(CupertinoIcons.back), + icon: new Icon(CupertinoIcons.back, color: primaryColor), onPressed: () => Navigator.of(context).pop(), ), - backgroundColor: primaryColor, - title: LocalText( - context, - "rate.title", - color: Colors.white, - fontSize: 18, - ), + backgroundColor: Colors.white, + shadowColor: Colors.transparent, + title: LocalText(context, 'rate.title', + color: primaryColor, fontSize: 20), + actions: isEditable + ? [ + IconButton( + onPressed: () => Navigator.of(context).push( + CupertinoPageRoute( + builder: (context) => ShipmentRatesEdit())), + icon: Icon( + CupertinoIcons.pen, + color: primaryColor, + )) + ] + : [], ), body: Padding( padding: const EdgeInsets.all(8.0), child: ListView( // crossAxisAlignment: CrossAxisAlignment.center, children: [ + fcsButton(context, "Calculate shipping cost", callack: () { + Navigator.of(context).push(CupertinoPageRoute( + builder: (context) => ShipmentRatesCal())); + }), + Divider( + color: Colors.grey, + ), Container( padding: EdgeInsets.only(left: 25, top: 10), child: Text( @@ -71,30 +91,8 @@ class _ShipmentRatesState extends State { fontSize: 15), ), ), - Container( - height: 135, - child: Column( - children: getCargoWidget(shipmentRateModel.rates), - ), - ), - Divider( - color: Colors.grey, - ), - Container( - padding: EdgeInsets.only(left: 25, top: 10), - child: Text( - "Custom Duties", - style: TextStyle( - color: primaryColor, - fontWeight: FontWeight.bold, - fontSize: 15), - ), - ), - Container( - height: 100, - child: Column( - children: getCustonWidget(shipmentRateModel.customs), - ), + Column( + children: getCargoWidget(shipmentRateModel.rate.cargoTypes), ), Divider( color: Colors.grey, @@ -109,33 +107,35 @@ class _ShipmentRatesState extends State { fontSize: 15), ), ), - Container( - height: 100, - child: Column( - children: - getDiscountWidget(shipmentRateModel.discountsByWeight), - ), + Column( + children: + getDiscountWidget(shipmentRateModel.rate.discountByWeights), ), Divider( color: Colors.grey, ), - _row("Free delivery within Yangon \nfor shipments over", "10", - "pounds"), - _row("Delivery fees", "\$ 5", "below 10 pounds"), - _row("Volumetric Ratio", "166.36", "in3 per pound"), - // fcsButton(context, "Terms & Conditions", callack: () { - // Navigator.of(context) - // .push(MaterialPageRoute(builder: (_) => Term())); - // }), - fcsButton(context, "Estimate shipping cost", callack: () { - Navigator.of(context).push(CupertinoPageRoute( - builder: (context) => ShipmentRatesCal())); - }), - fcsButton(context, "Edit", callack: () { - Navigator.of(context).push(CupertinoPageRoute( - builder: (context) => ShipmentRatesEdit())); - }), - SizedBox(height: 10) + _row("Free delivery within Yangon \nfor shipments over", + "${rate.freeDeliveryWeight}", "pounds"), + _row("Delivery fees", "\$ ${rate.deliveryFee}", + "below ${rate.freeDeliveryWeight} pounds"), + _row("Volumetric Ratio", "${rate.volumetricRatio}", + "in3 per pound"), + Divider( + color: Colors.grey, + ), + Container( + padding: EdgeInsets.only(left: 25, top: 10), + child: Text( + "Custom Duties", + style: TextStyle( + color: primaryColor, + fontWeight: FontWeight.bold, + fontSize: 15), + ), + ), + Column( + children: getCustonWidget(shipmentRateModel.rate.customDuties), + ), ], ), ), @@ -143,16 +143,15 @@ class _ShipmentRatesState extends State { ); } - List getCargoWidget(List rates) { - return rates.map((cargo) { + List getCargoWidget(List cargos) { + return cargos.map((cargo) { return Container( - child: _row( - cargo.description, "\$ " + cargo.price.toString(), 'per pound'), + child: _row(cargo.name, "\$ " + cargo.rate.toString(), 'per pound'), ); }).toList(); } - List getCustonWidget(List customs) { + List getCustonWidget(List customs) { return customs.map((c) { return Container( child: _row(c.productType, "\$ " + c.fee.toString(), ''), @@ -160,11 +159,12 @@ class _ShipmentRatesState extends State { }).toList(); } - List getDiscountWidget(List discounts) { + List getDiscountWidget(List discounts) { + if (discounts == null) return []; return discounts.map((d) { return Container( child: _row( - "${d.weight.toString()} lb", "\$ " + d.discountRate.toString(), ''), + "${d.weight.toString()} lb", "\$ " + d.discount.toString(), ''), ); }).toList(); } diff --git a/lib/pages/rates/shipment_rates_calculate.dart b/lib/pages/rates/shipment_rates_calculate.dart index 202426b..f1a1257 100644 --- a/lib/pages/rates/shipment_rates_calculate.dart +++ b/lib/pages/rates/shipment_rates_calculate.dart @@ -1,6 +1,7 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/localization/app_translations.dart'; import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; +import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:provider/provider.dart'; @@ -38,11 +39,13 @@ class _ShipmentRatesCalState extends State { appBar: AppBar( centerTitle: true, leading: new IconButton( - icon: new Icon(CupertinoIcons.back), + icon: new Icon(CupertinoIcons.back, color: primaryColor), onPressed: () => Navigator.of(context).pop(), ), - backgroundColor: primaryColor, - title: Text(AppTranslations.of(context).text("rate.cal.title")), + backgroundColor: Colors.white, + shadowColor: Colors.transparent, + title: LocalText(context, 'rate.cal.title', + color: primaryColor, fontSize: 20), ), body: Padding( padding: const EdgeInsets.all(8.0), @@ -60,12 +63,11 @@ class _ShipmentRatesCalState extends State { child: DropdownButtonFormField( decoration: InputDecoration( fillColor: Colors.white, - hintText: shipmentRateModel.rates[0].description, + hintText: shipmentRateModel.rate.cargoTypes[0].name, hintStyle: TextStyle(color: Colors.black87)), - items: shipmentRateModel.rates + items: shipmentRateModel.rate.cargoTypes .map((e) => DropdownMenuItem( - child: Text(e.description), - value: e.description)) + child: Text(e.name), value: e.name)) .toList(), onChanged: (selected) => { setState(() { diff --git a/lib/pages/rates/shipment_rates_edit.dart b/lib/pages/rates/shipment_rates_edit.dart index 51d119e..f9ca5f4 100644 --- a/lib/pages/rates/shipment_rates_edit.dart +++ b/lib/pages/rates/shipment_rates_edit.dart @@ -1,6 +1,7 @@ -import 'package:fcs/domain/entities/custom.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; +import 'package:fcs/domain/entities/custom_duty.dart'; import 'package:fcs/domain/entities/discount.dart'; -import 'package:fcs/domain/entities/discount_rate.dart'; +import 'package:fcs/domain/entities/discount_by_weight.dart'; import 'package:fcs/domain/entities/rate.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/localization/app_translations.dart'; @@ -118,7 +119,8 @@ class _ShipmentRatesEditState extends State { fontSize: 15, color: Colors.grey[600]))), ], - rows: getCargoRows(shipmentRateModel.rates), + rows: getCargoRows( + shipmentRateModel.rate.cargoTypes), ), ), ), @@ -182,7 +184,8 @@ class _ShipmentRatesEditState extends State { fontSize: 15, color: Colors.grey[600]))), ], - rows: getCustomsRows(shipmentRateModel.customs), + rows: getCustomsRows( + shipmentRateModel.rate.customDuties), ), ), ), @@ -247,7 +250,7 @@ class _ShipmentRatesEditState extends State { color: Colors.grey[600]))), ], rows: getDiscounts( - shipmentRateModel.discountsByWeight), + shipmentRateModel.rate.discountByWeights), ), ), ), @@ -296,25 +299,25 @@ class _ShipmentRatesEditState extends State { ); } - List getCargoRows(List rates) { - return rates.map((r) { + List getCargoRows(List cargos) { + return cargos.map((r) { return MyDataRow( onSelectChanged: (selected) { Navigator.push( context, - CupertinoPageRoute(builder: (context) => CargoEditor(rate: r)), + CupertinoPageRoute(builder: (context) => CargoEditor(cargo: r)), ); }, cells: [ MyDataCell( new Text( - r.description, + r.name, style: textStyle, ), ), MyDataCell( new Text( - r.price.toString(), + r.rate.toString(), style: textStyle, ), ), @@ -324,7 +327,7 @@ class _ShipmentRatesEditState extends State { }).toList(); } - List getCustomsRows(List customs) { + List getCustomsRows(List customs) { return customs.map((c) { return MyDataRow( onSelectChanged: (selected) { @@ -352,7 +355,7 @@ class _ShipmentRatesEditState extends State { }).toList(); } - List getDiscounts(List discounts) { + List getDiscounts(List discounts) { return discounts.map((d) { return MyDataRow( onSelectChanged: (selected) { @@ -371,7 +374,7 @@ class _ShipmentRatesEditState extends State { MyDataCell( Center( child: new Text( - d.discountRate.toString(), + d.discount.toString(), style: textStyle, ), ), diff --git a/lib/pages/shipment/model/shipment_model.dart b/lib/pages/shipment/model/shipment_model.dart index a20558f..11117b2 100644 --- a/lib/pages/shipment/model/shipment_model.dart +++ b/lib/pages/shipment/model/shipment_model.dart @@ -2,8 +2,8 @@ import 'dart:async'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:fcs/domain/constants.dart'; -import 'package:fcs/domain/entities/cargo.dart'; -import 'package:fcs/domain/entities/pickup.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; +import 'package:fcs/domain/entities/shipment.dart'; import 'package:fcs/domain/vo/radio.dart'; import 'package:fcs/pages/main/model/base_model.dart'; import 'package:logging/logging.dart'; @@ -78,9 +78,9 @@ class ShipmentModel extends BaseModel { isCourier: true, radioIndex: 2, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Shipment( id: "S200125 - 12 May 2020", @@ -95,9 +95,9 @@ class ShipmentModel extends BaseModel { address: '154-19 64th Ave.\nFlushing, NY 11367', handlingFee: 50, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Shipment( id: "S200441 - 13 Apr 2020", @@ -113,9 +113,9 @@ class ShipmentModel extends BaseModel { handlingFee: 50, radioIndex: 3, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Shipment( id: "S200412 - 12 Apr 2020", @@ -130,9 +130,9 @@ class ShipmentModel extends BaseModel { address: '154-19 64th Ave.\nFlushing, NY 11367', handlingFee: 50, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Shipment( id: "S200125 - 12 May 2020", @@ -147,9 +147,9 @@ class ShipmentModel extends BaseModel { address: '154-19 64th Ave.\nFlushing, NY 11367', handlingFee: 50, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Shipment( id: "S200441 - 13 Apr 2020", @@ -164,9 +164,9 @@ class ShipmentModel extends BaseModel { address: '154-19 64th Ave.\nFlushing, NY 11367', handlingFee: 50, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Shipment( id: "S200441 - 10 Apr 2020", @@ -181,9 +181,9 @@ class ShipmentModel extends BaseModel { address: '154-19 64th Ave.\nFlushing, NY 11367', handlingFee: 50, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Shipment( id: "S200441 - 6 Apr 2020", @@ -198,9 +198,9 @@ class ShipmentModel extends BaseModel { address: '154-19 64th Ave.\nFlushing, NY 11367', handlingFee: 50, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), ]; return pickups; @@ -222,9 +222,9 @@ class ShipmentModel extends BaseModel { isCourier: true, radioIndex: 2, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Shipment( id: "S200125 - 12 May 2020", @@ -239,9 +239,9 @@ class ShipmentModel extends BaseModel { address: '154-19 64th Ave.\nFlushing, NY 11367', handlingFee: 50, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Shipment( id: "S200441 - 13 Apr 2020", @@ -257,9 +257,9 @@ class ShipmentModel extends BaseModel { handlingFee: 50, radioIndex: 3, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Shipment( id: "S200412 - 12 Apr 2020", @@ -274,9 +274,9 @@ class ShipmentModel extends BaseModel { address: '154-19 64th Ave.\nFlushing, NY 11367', handlingFee: 50, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Shipment( id: "S200125 - 12 May 2020", @@ -291,9 +291,9 @@ class ShipmentModel extends BaseModel { address: '154-19 64th Ave.\nFlushing, NY 11367', handlingFee: 50, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Shipment( id: "S200441 - 13 Apr 2020", @@ -308,9 +308,9 @@ class ShipmentModel extends BaseModel { address: '154-19 64th Ave.\nFlushing, NY 11367', handlingFee: 50, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Shipment( id: "S200441 - 10 Apr 2020", @@ -325,9 +325,9 @@ class ShipmentModel extends BaseModel { address: '154-19 64th Ave.\nFlushing, NY 11367', handlingFee: 50, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), Shipment( id: "S200441 - 6 Apr 2020", @@ -342,9 +342,9 @@ class ShipmentModel extends BaseModel { address: '154-19 64th Ave.\nFlushing, NY 11367', handlingFee: 50, cargoTypes: [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]), ]; diff --git a/lib/pages/shipment/shipment_box_editor.dart b/lib/pages/shipment/shipment_box_editor.dart index 1e4d6cf..c838e64 100644 --- a/lib/pages/shipment/shipment_box_editor.dart +++ b/lib/pages/shipment/shipment_box_editor.dart @@ -1,10 +1,11 @@ import 'package:fcs/domain/entities/box.dart'; -import 'package:fcs/domain/entities/cargo.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/box/cargo_type_editor.dart'; import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart'; import 'package:fcs/pages/main/model/main_model.dart'; +import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; import 'package:fcs/pages/widgets/defalut_delivery_address.dart'; import 'package:fcs/pages/widgets/delivery_address_selection.dart'; @@ -39,14 +40,15 @@ class _ShipmentBoxEditorState extends State { DeliveryAddress _deliveryAddress; double volumetricRatio = 0; double shipmentWeight = 0; - List cargos = []; + List cargos = []; @override void initState() { super.initState(); - volumetricRatio = - Provider.of(context, listen: false).setting.volumetricRatio; + volumetricRatio = Provider.of(context, listen: false) + .rate + .volumetricRatio; if (widget.box != null) { _box = widget.box; @@ -145,7 +147,7 @@ class _ShipmentBoxEditorState extends State { color: primaryColor, ), onPressed: () async { - Cargo cargo = await Navigator.push( + CargoType cargo = await Navigator.push( context, CupertinoPageRoute( builder: (context) => CargoTypeEditor())); @@ -212,7 +214,7 @@ class _ShipmentBoxEditorState extends State { total += c.weight; return MyDataRow( onSelectChanged: (bool selected) async { - Cargo cargo = await Navigator.push( + CargoType cargo = await Navigator.push( context, CupertinoPageRoute( builder: (context) => CargoTypeEditor( @@ -222,7 +224,7 @@ class _ShipmentBoxEditorState extends State { }, cells: [ MyDataCell(new Text( - c.type == null ? "" : c.type, + c.name == null ? "" : c.name, style: textStyle, )), MyDataCell( @@ -270,7 +272,7 @@ class _ShipmentBoxEditorState extends State { return rows; } - _addCargo(Cargo cargo) { + _addCargo(CargoType cargo) { if (cargo == null) return; setState(() { cargos.remove(cargo); @@ -278,7 +280,7 @@ class _ShipmentBoxEditorState extends State { }); } - _removeCargo(Cargo cargo) { + _removeCargo(CargoType cargo) { setState(() { cargos.remove(cargo); }); diff --git a/lib/pages/shipment/shipment_editor.dart b/lib/pages/shipment/shipment_editor.dart index 310806d..c4d7838 100644 --- a/lib/pages/shipment/shipment_editor.dart +++ b/lib/pages/shipment/shipment_editor.dart @@ -1,7 +1,7 @@ import 'package:fcs/domain/constants.dart'; import 'package:fcs/domain/entities/box.dart'; -import 'package:fcs/domain/entities/cargo.dart'; -import 'package:fcs/domain/entities/pickup.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; +import 'package:fcs/domain/entities/shipment.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/box/model/box_model.dart'; @@ -93,10 +93,10 @@ class _ShipmentEditorState extends State { _pickupDate.text = dateFormatter.format(now); _fromTimeEditingController.text = "${(now.hour)}:${(now.minute)}"; _toTimeEditingController.text = "${(now.hour)}:${(now.minute)}"; - List _cargoTypes = [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) + List _cargoTypes = [ + CargoType(name: 'General Cargo', weight: 25), + CargoType(name: 'Medicine', weight: 20), + CargoType(name: 'Dangerous Cargo', weight: 30) ]; _pickUp = Shipment(cargoTypes: _cargoTypes); } diff --git a/lib/pages/shipment/shipment_list_row.dart b/lib/pages/shipment/shipment_list_row.dart index 4f167a3..89e7da9 100644 --- a/lib/pages/shipment/shipment_list_row.dart +++ b/lib/pages/shipment/shipment_list_row.dart @@ -1,4 +1,4 @@ -import 'package:fcs/domain/entities/pickup.dart'; +import 'package:fcs/domain/entities/shipment.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; import 'package:flutter/cupertino.dart'; @@ -41,8 +41,8 @@ class _ShipmentListRowState extends State { padding: EdgeInsets.only(left: 15, right: 15), child: InkWell( onTap: () { - Navigator.of(context) - .push(CupertinoPageRoute(builder: (context) => ShipmentEditor(shipment: _pickUp))); + Navigator.of(context).push(CupertinoPageRoute( + builder: (context) => ShipmentEditor(shipment: _pickUp))); }, child: Row( children: [ diff --git a/lib/pages/widgets/delivery_address_selection.dart b/lib/pages/widgets/delivery_address_selection.dart index 73d5fb8..87e52f4 100644 --- a/lib/pages/widgets/delivery_address_selection.dart +++ b/lib/pages/widgets/delivery_address_selection.dart @@ -23,16 +23,13 @@ class DeliveryAddressSelection extends StatelessWidget { appBar: AppBar( centerTitle: true, leading: new IconButton( - icon: new Icon(CupertinoIcons.back), - onPressed: () => Navigator.pop(context), - ), - backgroundColor: primaryColor, - title: LocalText( - context, - "delivery_addresses", - fontSize: 20, - color: Colors.white, + icon: new Icon(CupertinoIcons.back, color: primaryColor), + onPressed: () => Navigator.of(context).pop(), ), + backgroundColor: Colors.white, + shadowColor: Colors.transparent, + title: LocalText(context, 'delivery_addresses', + color: primaryColor, fontSize: 20), ), floatingActionButton: FloatingActionButton.extended( onPressed: () {