From e032cee9225beb3a03bc7942b3825d4d59505262 Mon Sep 17 00:00:00 2001 From: Sai Naw Wun Date: Tue, 13 Oct 2020 07:50:25 +0630 Subject: [PATCH] add shipments --- assets/local/localization_en.json | 12 +- assets/local/localization_mu.json | 14 +- lib/data/provider/package_data_provider.dart | 7 + lib/data/services/package_imp.dart | 5 + lib/data/services/package_service.dart | 1 + lib/domain/entities/box.dart | 13 + lib/domain/entities/cargo.dart | 11 + lib/domain/entities/package.dart | 5 +- lib/domain/entities/setting.dart | 45 +- lib/pages/box/box_editor.dart | 3 +- lib/pages/box/cargo_type_editor.dart | 40 +- lib/pages/customer/customer_editor.dart | 6 +- .../delivery_address_list.dart | 39 +- .../model/delivery_address_model.dart | 9 + .../fcs_shipment/fcs_shipment_editor.dart | 15 +- lib/pages/package/model/package_model.dart | 7 + lib/pages/package/package_info.dart | 90 ++- lib/pages/profile/profile_page.dart | 47 +- lib/pages/shipment/box_row.dart | 132 ++++ lib/pages/shipment/pickup_box_editor.dart | 328 ---------- lib/pages/shipment/shipment_box_editor.dart | 336 ++++++++++ lib/pages/shipment/shipment_editor.dart | 573 +++--------------- lib/pages/shipment/shipment_list.dart | 81 --- lib/pages/widgets/callbacks.dart | 2 + .../widgets/defalut_delivery_address.dart | 56 ++ .../widgets/delivery_address_selection.dart | 85 +++ lib/pages/widgets/fcs_expansion_tile.dart | 2 +- lib/pages/widgets/local_button.dart | 56 ++ lib/pages/widgets/local_dropdown.dart | 68 +++ lib/pages/widgets/multi_img_controller.dart | 3 +- lib/pages/widgets/title_with_add_button.dart | 52 ++ 31 files changed, 1108 insertions(+), 1035 deletions(-) create mode 100644 lib/pages/shipment/box_row.dart delete mode 100644 lib/pages/shipment/pickup_box_editor.dart create mode 100644 lib/pages/shipment/shipment_box_editor.dart create mode 100644 lib/pages/widgets/callbacks.dart create mode 100644 lib/pages/widgets/defalut_delivery_address.dart create mode 100644 lib/pages/widgets/delivery_address_selection.dart create mode 100644 lib/pages/widgets/local_button.dart create mode 100644 lib/pages/widgets/local_dropdown.dart create mode 100644 lib/pages/widgets/title_with_add_button.dart diff --git a/assets/local/localization_en.json b/assets/local/localization_en.json index 1a809ba..50dd6d6 100644 --- a/assets/local/localization_en.json +++ b/assets/local/localization_en.json @@ -154,6 +154,7 @@ "profile.devices":"Devices", "profile.email":"Email", "profile.privileges":"Privileges", + "profile.default.delivery.address":"Default Delivery Address", "Profile End ================================================================":"", "Package Start ================================================================":"", @@ -179,6 +180,7 @@ "package.rate":"Rate", "package.weight":"Weight", "package.amount":"Amount", + "package.delivery.address":"Delivery Address", "package.popupmenu.active":"Active Packages", "package.popupmenu.delivered":"Delivered Packages", "Package End ================================================================":"", @@ -292,7 +294,7 @@ "Shipment Start ================================================================":"", "shipment": "Shipments", "shipment.title": "Shipments", - "shipment.new": "New Shipment", + "shipment.new": "Request Shipment", "shipment.new.title": "New Shipment", "shipment.edit.title": "Edit Shipment", "shipment.type": "Pickup/Drop-off", @@ -305,6 +307,14 @@ "shipment.from":"From", "shipment.to":"To", "shipment.box.delivery":"Delivery Address", + "shipment.handling.fee":"Handling Fee/Courier Fee", + "shipment.box.cargo.type":"Cargo Types", + "shipment.box.dimemsion":"Dimension", + "shipment.box.shipment.weight":"Shipment Weight", + "shipment.box.length":"Length", + "shipment.box.width":"Width", + "shipment.box.height":"Height", + "shipment.box.add":"Add Box", "Shipment End ================================================================":"", "Rate Start ================================================================":"", diff --git a/assets/local/localization_mu.json b/assets/local/localization_mu.json index 79c720f..a947745 100644 --- a/assets/local/localization_mu.json +++ b/assets/local/localization_mu.json @@ -154,6 +154,7 @@ "profile.devices":"ဖုန်းမော်ဒယ်အမျိုးအစားများ", "profile.email":"အီးမေးလ်", "profile.privileges":"လုပ်ပိုင်ခွင့်များ", + "profile.default.delivery.address":"အမြဲတမ်း ပို့ဆောင်ရမည့်လိပ်စာ", "Profile End ================================================================":"", "Package Start ================================================================":"", @@ -179,6 +180,7 @@ "package.rate":"Rate", "package.weight":"Weight", "package.amount":"Amount", + "package.delivery.address":"ပို့ဆောင်ရမည့်လိပ်စာ", "package.popupmenu.active":"လာမည့် အထုပ်များ", "package.popupmenu.delivered":"ပို့ပြီးသော အထုပ်များ", "Package End ================================================================":"", @@ -305,6 +307,14 @@ "shipment.from":"From", "shipment.to":"To", "shipment.box.delivery":"Delivery Address", + "shipment.handling.fee":"Handling Fee/Courier Fee", + "shipment.box.cargo.type":"Cargo Types", + "shipment.box.dimemsion":"Dimension", + "shipment.box.shipment.weight":"Shipment Weight", + "shipment.box.length":"Length", + "shipment.box.width":"Width", + "shipment.box.height":"Height", + "shipment.box.add":"Add Box", "Shipment End ================================================================":"", "Rate Start ================================================================":"", @@ -373,7 +383,7 @@ "delivery_addresses Start ================================================================":"", "delivery_addresses": "ပို့ဆောင်ရမည့်လိပ်စာများ", - "delivery_address": "ပို့ဆောင်ရမည့်လိပ်စာ", + "delivery_address": "အမြဲတမ်း ပို့ဆောင်ရမည့် လိပ်စာ", "delivery_address.full_name": "နာမည် အပြည့်အစုံ", "delivery_address.address_line1": "လိပ်စာ ၁", "delivery_address.address_line2": "လိပ်စာ ၂", @@ -384,7 +394,7 @@ "delivery_address.create": "ပြုလုပ်ရန်", "delivery_address.update": "ပြုပြင်ရန်", "delivery_address.new_address":"လိပ်စာ အသစ်", - "delivery_address.change_address": "လိပ်စာပြောင်းပါ", + "delivery_address.change_address": "လိပ်စာပြောင်းမည်", "delivery_address.delete.confirm":"ပို့ဆောင်ရမည့်လိပ်စာကို ဖျက်မလား?", "delivery_addresses End ================================================================":"", diff --git a/lib/data/provider/package_data_provider.dart b/lib/data/provider/package_data_provider.dart index 4ccf220..469f243 100644 --- a/lib/data/provider/package_data_provider.dart +++ b/lib/data/provider/package_data_provider.dart @@ -41,6 +41,13 @@ class PackageDataProvider { payload: {"id": package.id}, token: await getToken()); } + Future changeDeliveryAddress( + String packageID, String deliveryID) async { + return await requestAPI("/packages/change_delivery_address", "PUT", + payload: {"package_id": packageID, "deliver_address_id": deliveryID}, + token: await getToken()); + } + Future> searchPackage(String term) async { if (term == null || term == '') return List(); diff --git a/lib/data/services/package_imp.dart b/lib/data/services/package_imp.dart index db8ae62..ed3e2e7 100644 --- a/lib/data/services/package_imp.dart +++ b/lib/data/services/package_imp.dart @@ -48,4 +48,9 @@ class PackageServiceImp implements PackageService { Future deleteProcessing(Package package) { return packageDataProvider.deleteProcessing(package); } + + @override + Future changeDeliveryAddress(String packageID, String deliveryID) { + return packageDataProvider.changeDeliveryAddress(packageID, deliveryID); + } } diff --git a/lib/data/services/package_service.dart b/lib/data/services/package_service.dart index c16dced..d91765f 100644 --- a/lib/data/services/package_service.dart +++ b/lib/data/services/package_service.dart @@ -8,4 +8,5 @@ abstract class PackageService { Future updateProcessing(Package package); Future deleteProcessing(Package package); Future> searchPackage(String term); + Future changeDeliveryAddress(String packageID, String deliveryID); } diff --git a/lib/domain/entities/box.dart b/lib/domain/entities/box.dart index 3b9fc97..161336a 100644 --- a/lib/domain/entities/box.dart +++ b/lib/domain/entities/box.dart @@ -41,6 +41,19 @@ class Box { shipmentNumber + "-" + receiverNumber + " #" + boxNumber; double get price => rate.toDouble() * weight; + double getShipmentWeight(double volumetricRatio) { + if (length == null || + length <= 0 || + width == null || + width <= 0 || + height == null || + height <= 0 || + volumetricRatio == null || + volumetricRatio <= 0) return 0; + + return (length * width * height) / volumetricRatio; + } + List shipmentHistory; Box( diff --git a/lib/domain/entities/cargo.dart b/lib/domain/entities/cargo.dart index c892aec..746eee6 100644 --- a/lib/domain/entities/cargo.dart +++ b/lib/domain/entities/cargo.dart @@ -3,4 +3,15 @@ class Cargo { 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/package.dart b/lib/domain/entities/package.dart index 8af6895..25679c6 100644 --- a/lib/domain/entities/package.dart +++ b/lib/domain/entities/package.dart @@ -13,6 +13,7 @@ class Package { List photoUrls; List shipmentHistory; String desc; + String deliveryAddressID; String status; String shipmentNumber; @@ -70,7 +71,8 @@ class Package { this.currentStatusDate, this.photoUrls, this.desc, - this.isChecked =false}); + this.deliveryAddressID, + this.isChecked = false}); factory Package.fromMap(Map map, String docID) { var _currentStatusDate = (map['current_status_date'] as Timestamp); @@ -92,6 +94,7 @@ class Package { remark: map['remark'], desc: map['desc'], currentStatus: map['current_status'], + deliveryAddressID: map['delivery_address_id'], currentStatusDate: _currentStatusDate != null ? _currentStatusDate.toDate() : null, photoUrls: _photoUrls, diff --git a/lib/domain/entities/setting.dart b/lib/domain/entities/setting.dart index 8a203ee..242f5f8 100644 --- a/lib/domain/entities/setting.dart +++ b/lib/domain/entities/setting.dart @@ -1,3 +1,6 @@ +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'), @@ -23,24 +26,32 @@ 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, - }); + 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}); factory Setting.fromMap(Map map) { return Setting( @@ -56,7 +67,11 @@ 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/pages/box/box_editor.dart b/lib/pages/box/box_editor.dart index 8d48fff..d053605 100644 --- a/lib/pages/box/box_editor.dart +++ b/lib/pages/box/box_editor.dart @@ -585,8 +585,7 @@ class _BoxEditorState extends State { DeliveryAddress deliveryAddress = await Navigator.push( context, - BottomUpPageRoute(DeliveryAddressList( - deliveryAddress: _deliveryAddress)), + BottomUpPageRoute(DeliveryAddressList()), ); setState(() { _deliveryAddress = deliveryAddress; diff --git a/lib/pages/box/cargo_type_editor.dart b/lib/pages/box/cargo_type_editor.dart index 6c5aa5a..fe82800 100644 --- a/lib/pages/box/cargo_type_editor.dart +++ b/lib/pages/box/cargo_type_editor.dart @@ -1,12 +1,14 @@ import 'package:fcs/domain/entities/cargo.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/main/util.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'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:provider/provider.dart'; class CargoTypeEditor extends StatefulWidget { final Cargo cargo; @@ -17,7 +19,6 @@ class CargoTypeEditor extends StatefulWidget { } class _CargoTypeEditorState extends State { - TextEditingController _typeController = new TextEditingController(); TextEditingController _weightController = new TextEditingController(); bool _isLoading = false; @@ -28,11 +29,17 @@ class _CargoTypeEditorState extends State { super.initState(); if (widget.cargo != null) { _cargo = widget.cargo; - _typeController.text = _cargo.type; _weightController.text = _cargo.weight.toString(); + } else { + _loadDefalut(); } } + _loadDefalut() { + MainModel mainModel = Provider.of(context, listen: false); + _cargo = mainModel.setting.defaultCargoType; + } + @override void dispose() { super.dispose(); @@ -40,20 +47,33 @@ class _CargoTypeEditorState extends State { @override Widget build(BuildContext context) { - final typeBox = InputText( - labelTextKey: 'cargo.type', - iconData: Icons.text_format, - controller: _typeController); + MainModel mainModel = Provider.of(context); + List cargos = mainModel.setting.cargoTypesList; + final rateBox = InputText( labelTextKey: 'cargo.weight', iconData: FontAwesomeIcons.weightHanging, textInputType: TextInputType.number, controller: _weightController); - + + var cargoTypeBox = LocalDropdown( + callback: (v) { + setState(() { + _cargo = v; + }); + }, + iconData: Icons.text_format, + selectedValue: _cargo, + values: cargos, + ); + final saveBtn = fcsButton( context, getLocalString(context, 'box.cargo.save.btn'), - callack: () {}, + callack: () { + _cargo.weight = int.parse(_weightController.text, onError: (s) => 0); + Navigator.pop(context, _cargo); + }, ); return LocalProgress( inAsyncCall: _isLoading, @@ -76,7 +96,7 @@ class _CargoTypeEditorState extends State { padding: EdgeInsets.all(18), child: ListView( children: [ - typeBox, + cargoTypeBox, rateBox, SizedBox(height: 40), saveBtn, diff --git a/lib/pages/customer/customer_editor.dart b/lib/pages/customer/customer_editor.dart index ff17923..4a64df0 100644 --- a/lib/pages/customer/customer_editor.dart +++ b/lib/pages/customer/customer_editor.dart @@ -32,7 +32,7 @@ class _CustomerEditorState extends State { Expanded( child: DisplayText( text: widget.customer.phoneNumber, - labelTextKey: getLocalString(context, "customer.phone"), + labelTextKey: "customer.phone", iconData: Icons.phone, )), IconButton( @@ -72,12 +72,12 @@ class _CustomerEditorState extends State { phoneNumberBox, DisplayText( text: widget.customer.fcsID, - labelTextKey: getLocalString(context, "customer.fcs.id"), + labelTextKey: "customer.fcs.id", icon: FcsIDIcon(), ), DisplayText( text: widget.customer.status, - labelTextKey: getLocalString(context, "customer.status"), + labelTextKey: "customer.status", iconData: Icons.add_alarm, ), SizedBox( diff --git a/lib/pages/delivery_address/delivery_address_list.dart b/lib/pages/delivery_address/delivery_address_list.dart index 2d932b9..ba569df 100644 --- a/lib/pages/delivery_address/delivery_address_list.dart +++ b/lib/pages/delivery_address/delivery_address_list.dart @@ -12,12 +12,7 @@ import 'model/delivery_address_model.dart'; import 'delivery_address_row.dart'; class DeliveryAddressList extends StatefulWidget { - final DeliveryAddress deliveryAddress; - final bool forSelection; - - const DeliveryAddressList( - {Key key, this.deliveryAddress, this.forSelection = false}) - : super(key: key); + const DeliveryAddressList({Key key}) : super(key: key); @override _DeliveryAddressListState createState() => _DeliveryAddressListState(); } @@ -46,7 +41,7 @@ class _DeliveryAddressListState extends State { centerTitle: true, leading: new IconButton( icon: new Icon(Icons.close), - onPressed: () => Navigator.pop(context, widget.deliveryAddress), + onPressed: () => Navigator.pop(context), ), backgroundColor: primaryColor, title: LocalText( @@ -83,18 +78,15 @@ class _DeliveryAddressListState extends State { _row(BuildContext context, DeliveryAddress deliveryAddress) { return Row( children: [ - widget.forSelection - ? Container() - : InkWell( - onTap: () => _select(deliveryAddress), - child: Padding( - padding: const EdgeInsets.all(10.0), - child: Icon(Icons.check, - color: deliveryAddress.isDefault - ? primaryColor - : Colors.black26), - ), - ), + InkWell( + onTap: () => _select(deliveryAddress), + child: Padding( + padding: const EdgeInsets.all(10.0), + child: Icon(Icons.check, + color: + deliveryAddress.isDefault ? primaryColor : Colors.black26), + ), + ), Expanded( child: DeliveryAddressRow( key: ValueKey(deliveryAddress.id), @@ -106,11 +98,6 @@ class _DeliveryAddressListState extends State { } _edit(BuildContext context, DeliveryAddress deliveryAddress) { - if (widget.forSelection) { - Navigator.pop(context, deliveryAddress); - return; - } - Navigator.push( context, BottomUpPageRoute( @@ -119,10 +106,6 @@ class _DeliveryAddressListState extends State { } Future _select(DeliveryAddress deliveryAddress) async { - if (widget.forSelection) { - return; - } - if (deliveryAddress.isDefault) { Navigator.pop(context); return; diff --git a/lib/pages/delivery_address/model/delivery_address_model.dart b/lib/pages/delivery_address/model/delivery_address_model.dart index 2609061..550d6af 100644 --- a/lib/pages/delivery_address/model/delivery_address_model.dart +++ b/lib/pages/delivery_address/model/delivery_address_model.dart @@ -15,6 +15,9 @@ class DeliveryAddressModel extends BaseModel { DeliveryAddress get defalutAddress => deliveryAddresses.firstWhere((e) => e.isDefault, orElse: () => null); + DeliveryAddress getLocalDeliveryAddress(String id) => + deliveryAddresses.firstWhere((e) => e.id == id, orElse: () => null); + @override void privilegeChanged() { super.privilegeChanged(); @@ -52,6 +55,12 @@ class DeliveryAddressModel extends BaseModel { } } + Future getDeliveryAddress(String id) async { + String path = "/$user_collection/${user.id}/$delivery_address_collection"; + var snap = await Firestore.instance.collection(path).document(id).get(); + return DeliveryAddress.fromMap(snap.data, snap.documentID); + } + void initUser(user) { super.initUser(user); } diff --git a/lib/pages/fcs_shipment/fcs_shipment_editor.dart b/lib/pages/fcs_shipment/fcs_shipment_editor.dart index b2d9e8a..c221035 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_editor.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_editor.dart @@ -7,6 +7,7 @@ import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/widgets/display_text.dart'; import 'package:fcs/pages/widgets/input_date.dart'; import 'package:fcs/pages/widgets/input_text.dart'; +import 'package:fcs/pages/widgets/local_button.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/popupmenu.dart'; import 'package:fcs/pages/widgets/progress.dart'; @@ -71,16 +72,14 @@ class _FcsShipmentEditorState extends State { var languageModel = Provider.of(context); var mainModel = Provider.of(context); - final createBtn = fcsButton( - context, - getLocalString(context, "FCSshipment.create"), - callack: _create, + final createBtn = LocalButton( + textKey: "FCSshipment.create", + callBack: _create, ); - final updateBtn = fcsButton( - context, - getLocalString(context, "FCSshipment.update"), - callack: _update, + final updateBtn = LocalButton( + textKey: "FCSshipment.update", + callBack: _update, ); return LocalProgress( diff --git a/lib/pages/package/model/package_model.dart b/lib/pages/package/model/package_model.dart index e476ce6..140f655 100644 --- a/lib/pages/package/model/package_model.dart +++ b/lib/pages/package/model/package_model.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:io'; import 'package:fcs/data/services/services.dart'; +import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/domain/vo/message.dart'; import 'package:fcs/helpers/pagination.dart'; import 'package:path/path.dart' as Path; @@ -290,4 +291,10 @@ class PackageModel extends BaseModel { Future deleteProcessing(Package package) { return Services.instance.packageService.deleteProcessing(package); } + + Future changeDeliveryAddress( + Package package, DeliveryAddress deliveryAddress) { + return Services.instance.packageService + .changeDeliveryAddress(package.id, deliveryAddress.id); + } } diff --git a/lib/pages/package/package_info.dart b/lib/pages/package/package_info.dart index 9134a8a..6185a19 100644 --- a/lib/pages/package/package_info.dart +++ b/lib/pages/package/package_info.dart @@ -1,6 +1,13 @@ 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/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'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/multi_img_controller.dart'; @@ -27,6 +34,7 @@ class PackageInfo extends StatefulWidget { class _PackageInfoState extends State { var dateFormatter = new DateFormat('dd MMM yyyy'); Package _package; + DeliveryAddress _deliveryAddress; bool _isLoading = false; MultiImgController multiImgController = MultiImgController(); @@ -41,6 +49,12 @@ class _PackageInfoState extends State { _package = package; multiImgController.setImageUrls = package.photoUrls; }); + if (!widget.isSearchResult) { + DeliveryAddressModel deliveryAddressModel = + Provider.of(context, listen: false); + _deliveryAddress = deliveryAddressModel + .getLocalDeliveryAddress(package.deliveryAddressID); + } } @override @@ -50,6 +64,9 @@ class _PackageInfoState extends State { @override Widget build(BuildContext context) { + String id = Provider.of(context).user.id; + bool owner = _package.userID == id; + final trackingIdBox = DisplayText( text: _package.trackingID, labelTextKey: "package.tracking.id", @@ -85,6 +102,22 @@ class _PackageInfoState extends State { controller: multiImgController, title: "Receipt File", ); + final deliveryAddressBox = DefaultDeliveryAddress( + deliveryAddress: _deliveryAddress, + labelKey: "package.delivery.address", + onTap: owner + ? () async { + DeliveryAddress d = await Navigator.push( + context, + BottomUpPageRoute(DeliveryAddressSelection( + deliveryAddress: _deliveryAddress, + )), + ); + if (d == null) return; + _changeDeliverayAddress(d); + } + : null, + ); return LocalProgress( inAsyncCall: _isLoading, @@ -118,6 +151,7 @@ class _PackageInfoState extends State { _package.photoUrls.length == 0 ? Container() : img, widget.isSearchResult ? Container() : descBox, remarkBox, + deliveryAddressBox, StatusTree( shipmentHistory: _package.shipmentHistory, currentStatus: _package.currentStatus), @@ -133,37 +167,29 @@ class _PackageInfoState extends State { ); } - List _models() { - if (_package.shipmentHistory == null) return []; - return _package.shipmentHistory - .map((e) => TimelineModel( - Padding( - padding: const EdgeInsets.all(18.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(e.status, - style: TextStyle( - color: e.done ? primaryColor : Colors.grey, - fontSize: 16, - fontWeight: FontWeight.bold)), - Text(dateFormat.format(e.date)), - ], - ), - ), - iconBackground: e.done ? primaryColor : Colors.grey, - icon: Icon( - e.status == "shipped" - ? Ionicons.ios_airplane - : e.status == "delivered" - ? MaterialCommunityIcons.truck_fast - : e.status == "packed" - ? MaterialCommunityIcons.package - : e.status == "processed" - ? FontAwesome.dropbox - : MaterialCommunityIcons.inbox_arrow_down, - color: Colors.white, - ))) - .toList(); + _changeDeliverayAddress(DeliveryAddress deliveryAddress) async { + if (deliveryAddress == null) return; + setState(() { + _isLoading = true; + }); + PackageModel packageModel = + Provider.of(context, listen: false); + DeliveryAddressModel deliveryAddressModel = + Provider.of(context, listen: false); + + try { + await packageModel.changeDeliveryAddress(_package, deliveryAddress); + var da = + await deliveryAddressModel.getDeliveryAddress(deliveryAddress.id); + setState(() { + _deliveryAddress = da; + }); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + setState(() { + _isLoading = false; + }); + } } } diff --git a/lib/pages/profile/profile_page.dart b/lib/pages/profile/profile_page.dart index 5b9b454..306d6e6 100644 --- a/lib/pages/profile/profile_page.dart +++ b/lib/pages/profile/profile_page.dart @@ -12,6 +12,7 @@ import 'package:fcs/pages/profile/profile_currency_edit.dart'; import 'package:fcs/pages/profile/profile_edit.dart'; import 'package:fcs/pages/staff/model/staff_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'; import 'package:fcs/pages/widgets/fcs_id_icon.dart'; import 'package:fcs/pages/widgets/local_text.dart'; @@ -176,8 +177,14 @@ class _ProfileState extends State { ) ], ), - defalutDeliveryAddress( - context, deliveryAddressModel.defalutAddress), + DefaultDeliveryAddress( + labelKey: "profile.default.delivery.address", + deliveryAddress: deliveryAddressModel.defalutAddress, + onTap: () { + Navigator.push( + context, BottomUpPageRoute(DeliveryAddressList())); + }, + ), getPrivilegeBox(context), SizedBox(height: 15), logoutbutton, @@ -189,42 +196,6 @@ class _ProfileState extends State { ); } - Widget defalutDeliveryAddress( - BuildContext context, DeliveryAddress deliveryAddress) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Expanded( - child: DisplayText( - labelTextKey: "delivery_address", - iconData: MaterialCommunityIcons.truck_fast, - ), - ), - Chip( - label: InkWell( - onTap: () => Navigator.push( - context, - BottomUpPageRoute(DeliveryAddressList()), - ), - child: LocalText(context, "delivery_address.change_address", - color: primaryColor), - )) - ], - ), - Padding( - padding: const EdgeInsets.only(left: 28.0), - child: deliveryAddress == null - ? Container() - : DeliveryAddressRow( - key: ValueKey(deliveryAddress.id), - deliveryAddress: deliveryAddress), - ), - ], - ); - } - Widget getPrivilegeBox(BuildContext context) { User user = Provider.of(context, listen: false).user; List _privileges = diff --git a/lib/pages/shipment/box_row.dart b/lib/pages/shipment/box_row.dart new file mode 100644 index 0000000..b8c3b18 --- /dev/null +++ b/lib/pages/shipment/box_row.dart @@ -0,0 +1,132 @@ +import 'package:fcs/domain/entities/box.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +class BoxRow extends StatelessWidget { + final Box box; + + const BoxRow({Key key, this.box}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + padding: EdgeInsets.only(left: 10), + child: Column( + children: [ + Row( + children: [ + Expanded( + child: new Padding( + padding: const EdgeInsets.symmetric(vertical: 10.0), + child: new Row( + children: [ + new Expanded( + child: new Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: new Text( + box.shippingAddress.fullName == null + ? '' + : box.shippingAddress.fullName, + style: new TextStyle( + fontSize: 15.0, + color: Colors.black, + fontWeight: FontWeight.bold), + ), + ), + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: new Text( + box.shippingAddress.addressLine1 == null + ? '' + : box.shippingAddress.addressLine1, + style: new TextStyle( + fontSize: 14.0, color: Colors.grey), + ), + ), + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: new Text( + box.shippingAddress.addressLine2 == null + ? '' + : box.shippingAddress.addressLine2, + style: new TextStyle( + fontSize: 14.0, color: Colors.grey), + ), + ), + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: new Text( + box.shippingAddress.city == null + ? '' + : box.shippingAddress.city, + style: new TextStyle( + fontSize: 14.0, color: Colors.grey), + ), + ), + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: new Text( + box.shippingAddress.state == null + ? '' + : box.shippingAddress.state, + style: new TextStyle( + fontSize: 14.0, color: Colors.grey), + ), + ), + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: new Text( + box.shippingAddress.phoneNumber == null + ? '' + : "Phone:${box.shippingAddress.phoneNumber}", + style: new TextStyle( + fontSize: 14.0, color: Colors.grey), + ), + ), + ], + ), + ), + ], + ), + ), + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: new Text( + "L${box.length}xW${box.weight}xH${box.height}", + style: new TextStyle(fontSize: 15.0, color: Colors.black), + ), + ), + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: new Text( + box.weight == null + ? '' + : "Actual Weight:${box.weight.toString()}lb", + style: new TextStyle(fontSize: 14.0, color: Colors.grey), + ), + ), + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: new Text( + box.shipmentWeight == null + ? '' + : "Shipment Weight:${box.shipmentWeight.toString()}lb", + style: new TextStyle(fontSize: 14.0, color: Colors.grey), + ), + ), + ], + ) + ], + ), + ], + ), + ); + } +} diff --git a/lib/pages/shipment/pickup_box_editor.dart b/lib/pages/shipment/pickup_box_editor.dart deleted file mode 100644 index 5ed3b7c..0000000 --- a/lib/pages/shipment/pickup_box_editor.dart +++ /dev/null @@ -1,328 +0,0 @@ -import 'package:fcs/domain/entities/box.dart'; -import 'package:fcs/domain/entities/cargo.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/localization/app_translations.dart'; -import 'package:fcs/pages/delivery_address/delivery_address_list.dart'; -import 'package:fcs/pages/delivery_address/delivery_address_row.dart'; -import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart'; -import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; -import 'package:fcs/pages/widgets/display_text.dart'; -import 'package:fcs/pages/widgets/local_text.dart'; -import 'package:fcs/pages/widgets/my_data_table.dart'; -import 'package:fcs/pages/widgets/progress.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_icons/flutter_icons.dart'; -import 'package:provider/provider.dart'; - -import '../main/util.dart'; - -class PickupBoxEditor extends StatefulWidget { - final Box box; - PickupBoxEditor({this.box}); - - @override - _PickupBoxEditorState createState() => _PickupBoxEditorState(); -} - -class _PickupBoxEditorState extends State { - Box _box; - bool _isLoading = false; - - bool isNew; - - bool isMixBox = false; - DeliveryAddress _deliveryAddress = new DeliveryAddress(); - - @override - void initState() { - super.initState(); - if (widget.box != null) { - _box = widget.box; - _deliveryAddress = _box.shippingAddress; - - isNew = false; - } else { - List packages = [ - // PackageModel.packages[0], - // PackageModel.packages[1], - // PackageModel.packages[2] - ]; - - List _cargoTypes = [ - Cargo(type: 'General Cargo', weight: 25), - Cargo(type: 'Medicine', weight: 20), - Cargo(type: 'Dangerous Cargo', weight: 30) - ]; - - var shipmentModel = - Provider.of(context, listen: false); - _deliveryAddress = shipmentModel.deliveryAddresses[1]; - - isNew = true; - _box = Box( - rate: 0, - weight: 75, - width: 0, - height: 0, - length: 0, - packages: packages, - cargoTypes: _cargoTypes, - shipmentWeight: 0); - } - } - - @override - void dispose() { - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return LocalProgress( - inAsyncCall: _isLoading, - child: Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: new Icon(Icons.close), - onPressed: () => Navigator.of(context).pop(), - ), - backgroundColor: primaryColor, - title: Text(AppTranslations.of(context).text("package.edit.title")), - ), - body: Card( - child: Column( - children: [ - Expanded( - child: ListView( - children: [ - ExpansionTile( - title: Text( - 'Cargo Types', - style: TextStyle( - color: primaryColor, fontWeight: FontWeight.bold), - ), - children: [ - Padding( - padding: const EdgeInsets.only(left: 20.0, right: 20), - child: TextFormField( - initialValue: _box.weight.toString(), - textAlign: TextAlign.end, - decoration: InputDecoration( - fillColor: Colors.white, - labelText: 'Actual Weight', - filled: true, - icon: Icon(MaterialCommunityIcons.weight, - color: primaryColor), - )), - ), - Container( - padding: EdgeInsets.only(top: 10), - child: SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: MyDataTable( - headingRowHeight: 40, - columnSpacing: 120, - columns: [ - MyDataColumn( - label: LocalText( - context, - "cargo.type", - color: Colors.grey, - ), - ), - MyDataColumn( - label: LocalText( - context, - "cargo.weight", - color: Colors.grey, - ), - ), - ], - rows: getCargoRows(context), - ), - ), - ), - Container( - padding: EdgeInsets.only(top: 20), - child: Align( - alignment: Alignment.bottomRight, - child: FloatingActionButton.extended( - icon: Icon(Icons.add), - label: Text("Add Cargo"), - backgroundColor: primaryColor, - onPressed: () { - // Navigator.of(context).push( - // BottomUpPageRoute(PackageAddition())); - }, - ), - ), - ), - SizedBox(height: 25), - ], - ), - ExpansionTile( - title: Text( - 'Box Dimension', - style: TextStyle( - color: primaryColor, fontWeight: FontWeight.bold), - ), - children: [ - Padding( - padding: const EdgeInsets.only(left: 20.0, right: 20), - child: fcsInputReadOnly( - "Shipment Weight", MaterialCommunityIcons.weight, - value: _box.shipmentWeight.toString()), - ), - Padding( - padding: const EdgeInsets.only(left: 20.0, right: 20), - child: TextFormField( - initialValue: _box.width.toString(), - textAlign: TextAlign.end, - decoration: InputDecoration( - fillColor: Colors.white, - labelText: 'Width', - filled: true, - icon: Icon(FontAwesome.arrow_circle_right, - color: primaryColor), - )), - ), - Padding( - padding: const EdgeInsets.only(left: 20.0, right: 20), - child: TextFormField( - initialValue: _box.height.toString(), - textAlign: TextAlign.end, - decoration: InputDecoration( - fillColor: Colors.white, - labelText: 'Height', - filled: true, - icon: Icon(FontAwesome.arrow_circle_up, - color: primaryColor), - )), - ), - Padding( - padding: const EdgeInsets.only(left: 20.0, right: 20), - child: TextFormField( - initialValue: _box.length.toString(), - textAlign: TextAlign.end, - decoration: InputDecoration( - fillColor: Colors.white, - labelText: 'Length', - filled: true, - icon: Icon(FontAwesome.arrow_circle_left, - color: primaryColor), - )), - ), - SizedBox(height: 25), - ], - ), - makeLocation(context, _deliveryAddress), - ], - ), - ), - widget.box == null - ? Align( - alignment: Alignment.bottomCenter, - child: Center( - child: Container( - width: 250, - child: FlatButton( - child: Text('Create New Package'), - color: primaryColor, - textColor: Colors.white, - onPressed: () { - Navigator.pop(context); - }, - ), - ))) - : Container( - child: Column( - children: [ - Align( - alignment: Alignment.bottomCenter, - child: Center( - child: Container( - width: 250, - child: FlatButton( - child: Text('Update Package'), - color: primaryColor, - textColor: Colors.white, - onPressed: () { - Navigator.pop(context); - }, - ), - ))), - ], - )) - ], - ), - ), - ), - ); - } - - Widget makeLocation(BuildContext context, DeliveryAddress deliveryAddress) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Expanded( - child: DisplayText( - labelTextKey: "shipment.box.delivery", - iconData: MaterialCommunityIcons.truck_fast, - ), - ), - Chip( - label: InkWell( - onTap: () async { - DeliveryAddress d = await Navigator.push( - context, - BottomUpPageRoute(DeliveryAddressList( - forSelection: true, - )), - ); - setState(() { - this._deliveryAddress = d; - }); - }, - child: LocalText(context, "delivery_address.change_address", - color: primaryColor), - )) - ], - ), - Padding( - padding: const EdgeInsets.only(left: 28.0), - child: deliveryAddress == null - ? Container() - : DeliveryAddressRow( - key: ValueKey(deliveryAddress.id), - deliveryAddress: deliveryAddress), - ), - ], - ); - } - - List getCargoRows(BuildContext context) { - if (_box == null || _box.cargoTypes == null) { - return []; - } - return _box.cargoTypes.map((c) { - return MyDataRow( - onSelectChanged: (bool selected) {}, - cells: [ - MyDataCell(new Text( - c.type == null ? "" : c.type, - style: textStyle, - )), - MyDataCell( - new Text(c.weight == null ? "0" : c.weight.toString(), - style: textStyle), - ), - ], - ); - }).toList(); - } -} diff --git a/lib/pages/shipment/shipment_box_editor.dart b/lib/pages/shipment/shipment_box_editor.dart new file mode 100644 index 0000000..c26b8bd --- /dev/null +++ b/lib/pages/shipment/shipment_box_editor.dart @@ -0,0 +1,336 @@ +import 'package:fcs/domain/entities/box.dart'; +import 'package:fcs/domain/entities/cargo.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/box/cargo_type_editor.dart'; +import 'package:fcs/pages/delivery_address/delivery_address_list.dart'; +import 'package:fcs/pages/delivery_address/delivery_address_row.dart'; +import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart'; +import 'package:fcs/pages/main/model/main_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'; +import 'package:fcs/pages/widgets/input_text.dart'; +import 'package:fcs/pages/widgets/local_button.dart'; +import 'package:fcs/pages/widgets/local_text.dart'; +import 'package:fcs/pages/widgets/my_data_table.dart'; +import 'package:fcs/pages/widgets/progress.dart'; +import 'package:fcs/pages/widgets/title_with_add_button.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_icons/flutter_icons.dart'; +import 'package:provider/provider.dart'; + +class ShipmentBoxEditor extends StatefulWidget { + final Box box; + ShipmentBoxEditor({this.box}); + + @override + _ShipmentBoxEditorState createState() => _ShipmentBoxEditorState(); +} + +class _ShipmentBoxEditorState extends State { + TextEditingController _lengthCtl = new TextEditingController(); + TextEditingController _widthCtl = new TextEditingController(); + TextEditingController _heightCtl = new TextEditingController(); + + Box _box; + bool _isLoading = false; + bool _isNew; + bool isMixBox = false; + DeliveryAddress _deliveryAddress = new DeliveryAddress(); + double volumetricRatio; + double shipmentWeight; + List cargos; + + @override + void initState() { + super.initState(); + + volumetricRatio = + Provider.of(context, listen: false).setting.volumetricRatio; + shipmentWeight = 0; + cargos = []; + + if (widget.box != null) { + _box = widget.box; + _deliveryAddress = _box.shippingAddress; + + _isNew = false; + } else { + var shipmentModel = + Provider.of(context, listen: false); + _deliveryAddress = shipmentModel.defalutAddress; + + _isNew = true; + _box = Box(); + } + _lengthCtl.addListener(_calShipmentWeight); + _widthCtl.addListener(_calShipmentWeight); + _heightCtl.addListener(_calShipmentWeight); + } + + _calShipmentWeight() { + double l = double.parse(_lengthCtl.text, (s) => 0); + double w = double.parse(_widthCtl.text, (s) => 0); + double h = double.parse(_heightCtl.text, (s) => 0); + setState(() { + shipmentWeight = l * w * h / volumetricRatio; + }); + } + + @override + Widget build(BuildContext context) { + double iconSize = 32; + + final shipmentWeightBox = DisplayText( + labelTextKey: "shipment.box.shipment.weight", + text: shipmentWeight == null ? "" : shipmentWeight.toStringAsFixed(0), + iconData: MaterialCommunityIcons.weight, + ); + final lengthBox = InputText( + labelTextKey: "shipment.box.length", + controller: _lengthCtl, + textInputType: TextInputType.number, + iconData: FontAwesome.arrow_circle_right, + ); + final widthBox = InputText( + labelTextKey: "shipment.box.width", + controller: _widthCtl, + textInputType: TextInputType.number, + iconData: FontAwesome.arrow_circle_left, + ); + final heightBox = InputText( + labelTextKey: "shipment.box.height", + controller: _heightCtl, + textInputType: TextInputType.number, + iconData: FontAwesome.arrow_circle_up, + ); + final createBtn = LocalButton( + textKey: "shipment.box.add", + ); + return LocalProgress( + inAsyncCall: _isLoading, + child: Scaffold( + appBar: AppBar( + centerTitle: true, + leading: new IconButton( + icon: new Icon( + Icons.close, + color: primaryColor, + ), + onPressed: () => Navigator.of(context).pop(), + ), + shadowColor: Colors.transparent, + backgroundColor: Colors.white, + title: LocalText( + context, + _isNew ? "boxes.new" : "box.edit.title", + fontSize: 20, + color: primaryColor, + ), + ), + body: Padding( + padding: const EdgeInsets.all(8.0), + child: ListView( + children: [ + TitleWithAddButton( + iconData: MaterialCommunityIcons.briefcase_check, + titleKey: "shipment.box.cargo.type", + onTap: () async { + Cargo cargo = await Navigator.push( + context, BottomUpPageRoute(CargoTypeEditor())); + if (cargo != null) { + setState(() { + cargos.add(cargo); + }); + } + }), + MyDataTable( + headingRowHeight: 40, + columns: [ + MyDataColumn( + label: LocalText( + context, + "cargo.type", + color: Colors.grey, + ), + ), + MyDataColumn( + label: LocalText( + context, + "cargo.weight", + color: Colors.grey, + ), + ), + ], + rows: getCargoRows(context), + ), + SizedBox( + height: 30, + ), + TitleWithAddButton( + titleKey: "shipment.box.dimemsion", + ), + shipmentWeightBox, + lengthBox, + widthBox, + heightBox, + DefaultDeliveryAddress( + deliveryAddress: _deliveryAddress, + onTap: () async { + DeliveryAddress d = await Navigator.push( + context, + BottomUpPageRoute(DeliveryAddressSelection( + deliveryAddress: _deliveryAddress, + )), + ); + if (d == null) return; + setState(() { + this._deliveryAddress = d; + }); + }), + createBtn + ], + ), + ), + ), + ); + } + + List getRows(BuildContext context) { + if (cargos == null || cargos == null) { + return []; + } + int total = 0; + var rows = cargos.map((c) { + total += c.weight; + return TableRow( + children: [ + Text( + c.type == null ? "" : c.type, + style: textStyle, + ), + Align( + alignment: Alignment.centerRight, + child: Text(c.weight == null ? "0" : c.weight.toString(), + style: textStyle)), + IconButton(icon: Icon(Icons.remove), onPressed: () => {}) + ], + ); + }).toList(); + + var totalRow = TableRow( + children: [ + Align( + alignment: Alignment.centerRight, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Text("Total Weight", + style: TextStyle( + fontWeight: FontWeight.bold, + )), + ), + ), + Align( + alignment: Alignment.centerRight, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Text(total.toString(), + style: TextStyle(fontWeight: FontWeight.bold)), + )), + Container( + width: 50, + child: + new Text(" ", style: TextStyle(fontWeight: FontWeight.bold))), + ], + ); + rows.add(totalRow); + rows.insert( + 0, + TableRow(children: [ + Center( + child: Padding( + padding: const EdgeInsets.all(8.0), + child: LocalText( + context, + "cargo.type", + color: Colors.grey, + ), + ), + ), + Center( + child: Padding( + padding: const EdgeInsets.all(8.0), + child: LocalText( + context, + "cargo.weight", + color: Colors.grey, + ), + ), + ), + Text("") + ])); + return rows; + } + + List getCargoRows(BuildContext context) { + if (cargos == null || cargos == null) { + return []; + } + int total = 0; + var rows = cargos.map((c) { + total += c.weight; + return MyDataRow( + onSelectChanged: (bool selected) {}, + cells: [ + MyDataCell(new Text( + c.type == null ? "" : c.type, + style: textStyle, + )), + MyDataCell( + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Text(c.weight == null ? "0" : c.weight.toString(), + style: textStyle), + IconButton( + icon: Icon( + Icons.remove_circle, + color: primaryColor, + ), + onPressed: () => {}, + ) + ], + ), + ), + ], + ); + }).toList(); + + var totalRow = MyDataRow( + onSelectChanged: (bool selected) {}, + cells: [ + MyDataCell(Align( + alignment: Alignment.centerRight, + child: Text("Total Weight", + style: TextStyle( + fontWeight: FontWeight.bold, + )), + )), + MyDataCell( + Padding( + padding: const EdgeInsets.only(right: 45.0), + child: Align( + alignment: Alignment.centerRight, + child: Text(total.toString(), + style: TextStyle(fontWeight: FontWeight.bold))), + ), + ), + ], + ); + rows.add(totalRow); + return rows; + } +} diff --git a/lib/pages/shipment/shipment_editor.dart b/lib/pages/shipment/shipment_editor.dart index 36c94f3..5ae8d2b 100644 --- a/lib/pages/shipment/shipment_editor.dart +++ b/lib/pages/shipment/shipment_editor.dart @@ -4,32 +4,29 @@ import 'package:fcs/domain/entities/cargo.dart'; import 'package:fcs/domain/entities/pickup.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/localization/app_translations.dart'; import 'package:fcs/pages/box/model/box_model.dart'; -import 'package:fcs/pages/delivery_address/delivery_address_list.dart'; -import 'package:fcs/pages/delivery_address/delivery_address_row.dart'; import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart'; import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/shipment/model/shipment_model.dart'; -import 'package:fcs/pages/main/util.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'; import 'package:fcs/pages/widgets/input_date.dart'; -import 'package:fcs/pages/widgets/input_text.dart'; import 'package:fcs/pages/widgets/input_time.dart'; +import 'package:fcs/pages/widgets/local_dropdown.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/multi_img_controller.dart'; -import 'package:fcs/pages/widgets/multi_img_file.dart'; import 'package:fcs/pages/widgets/progress.dart'; -import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; +import 'package:fcs/pages/widgets/title_with_add_button.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_icons/flutter_icons.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; -import 'package:flutter/material.dart'; - -import 'pickup_box_editor.dart'; +import 'box_row.dart'; +import 'shipment_box_editor.dart'; class ShipmentEditor extends StatefulWidget { final Shipment shipment; @@ -85,12 +82,6 @@ class _ShipmentEditorState extends State { _pickupDate.text = dateFormatter.format(now); _handlingFeeController.text = numberFormatter.format(_pickUp.handlingFee); _currVal = _pickUp.radioIndex; - - var mainModel = Provider.of(context, listen: false); - // _recipientNameEditingController.text = mainModel.recipient.name; - // _recipientPhoneEditingController.text = mainModel.recipient.phoneNumber; - // _recipientAddressEditingController.text = - // mainModel.recipient.shippingAddress; } else { _isNew = true; List _cargoTypes = [ @@ -112,6 +103,9 @@ class _ShipmentEditorState extends State { @override Widget build(BuildContext context) { + MainModel mainModel = Provider.of(context); + ShipmentModel pickupModel = Provider.of(context); + final fromTimeBox = InputTime( labelTextKey: 'shipment.from', iconData: Icons.timer, @@ -120,18 +114,6 @@ class _ShipmentEditorState extends State { final toTimeBox = InputTime( labelTextKey: 'shipment.to', controller: _toTimeEditingController); - final fromTimeBoxReadOnly = fcsInputReadOnly( - 'From', - Icons.timer, - controller: _fromTimeEditingController, - ); - - final toTimeBoxReadOnly = fcsInputReadOnly( - 'To', - null, - controller: _toTimeEditingController, - ); - final pickupTimeBox = Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -151,37 +133,66 @@ class _ShipmentEditorState extends State { ], ); - final pickupTimeReadOnly = Padding( - padding: const EdgeInsets.only(left: 20.0), - child: Row( - children: [ - SizedBox(height: 5), - Container( - child: fromTimeBoxReadOnly, - width: 120, - ), - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: Text('-'), - ), - Container( - child: toTimeBoxReadOnly, - width: 120, - ), - ], - ), + final shipmentDateBox = InputDate( + labelTextKey: "shipment.date", + iconData: Icons.date_range, + controller: _pickupDate, + ); + final localDropoffAddress = DisplayText( + iconData: Icons.location_on, + labelTextKey: "Local Dropoff Address", + text: mainModel.setting.usaAddress); + final curierDropoffAddress = FloatingActionButton.extended( + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + onPressed: () {}, + icon: Icon(Icons.arrow_right), + label: Text( + 'Visit courier websie for nearest drop-off', + style: TextStyle(fontSize: 12), + ), + backgroundColor: primaryColor, + ); + var deliveryAddressBox = DefaultDeliveryAddress( + deliveryAddress: _pickupAddress, + labelKey: "shipment.location", + onTap: () async { + DeliveryAddress d = await Navigator.push( + context, + BottomUpPageRoute(DeliveryAddressSelection( + deliveryAddress: _pickupAddress, + )), + ); + if (d == null) return; + setState(() { + this._pickupAddress = d; + }); + }, ); - - MainModel mainModel = Provider.of(context); var boxModel = Provider.of(context); - + var handlingFeeBox = DisplayText( + labelTextKey: "shipment.handling.fee", + text: "10", + iconData: FontAwesomeIcons.moneyBill); + var shipmentTypeBox = LocalDropdown( + callback: (v) { + setState(() { + selectedPickupType = v; + }); + }, + iconData: SimpleLineIcons.direction, + selectedValue: selectedPickupType, + values: pickupModel.pickupTypes, + ); return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( appBar: AppBar( centerTitle: true, leading: new IconButton( - icon: new Icon(Icons.close), + icon: new Icon( + Icons.close, + color: primaryColor, + ), onPressed: () => Navigator.of(context).pop(), ), shadowColor: Colors.transparent, @@ -197,214 +208,38 @@ class _ShipmentEditorState extends State { padding: const EdgeInsets.all(10.0), child: ListView( children: [ - _isNew - ? Container() - : Center( - child: Padding( - padding: const EdgeInsets.only(left: 10.0, top: 8), - child: Text( - '#P200304', - style: TextStyle( - color: Colors.black87, - fontSize: 14, - fontWeight: FontWeight.bold), - ), - ), - ), - widget.shipment == null - ? Container() - : widget.shipment.isCourier - ? Padding( - padding: const EdgeInsets.only(left: 15.0), - child: fcsInputReadOnly("Handling Fee/Courier Fee", - FontAwesomeIcons.moneyBill, - controller: _handlingFeeController), - ) - : Padding( - padding: const EdgeInsets.only(left: 15.0), - child: fcsInputReadOnly("Handling Fee/Courier Fee", - FontAwesomeIcons.moneyBill, - controller: _handlingFeeController), - ), - makeDropdown(), - makeLocation(context, _pickupAddress), - InputDate( - labelTextKey: "shipment.date", - iconData: Icons.date_range, - controller: _pickupDate, - ), + handlingFeeBox, + shipmentTypeBox, + deliveryAddressBox, + shipmentDateBox, pickupTimeBox, - _currVal == 3 - ? Container( - child: DeliveryAddressRow( - deliveryAddress: DeliveryAddress( - fullName: 'FCS Office', - addressLine1: '154-19 64th Ave.', - addressLine2: 'Flushing', - city: 'NY', - state: 'NY', - phoneNumber: '+1 (292)215-2247'), - ), - ) - : _currVal == 4 - ? Container( - child: Column( - children: [ - Container( - padding: EdgeInsets.only( - top: 20, bottom: 15, right: 15), - child: Align( - alignment: Alignment.center, - child: Container( - width: 350, - height: 40, - child: FloatingActionButton.extended( - materialTapTargetSize: - MaterialTapTargetSize.shrinkWrap, - onPressed: () {}, - icon: Icon(Icons.arrow_right), - label: Text( - 'Visit courier websie for nearest drop-off', - style: TextStyle(fontSize: 12), - ), - backgroundColor: primaryColor, - ), - ), - ), - ), - ], - )) - : Container(), - Padding( - padding: const EdgeInsets.all(8.0), - child: Row( - children: [ - Text( - 'Boxes', - style: TextStyle( - color: primaryColor, fontWeight: FontWeight.bold), - ), - Spacer(), - IconButton( - onPressed: () { - Navigator.push( - context, - BottomUpPageRoute(PickupBoxEditor()), - ); - }, - icon: Icon( - Icons.add, - color: primaryColor, - )) - ], + localDropoffAddress, + curierDropoffAddress, + TitleWithAddButton( + titleKey: "boxes.name", + iconData: MaterialCommunityIcons.package, + onTap: () => Navigator.push( + context, + BottomUpPageRoute(ShipmentBoxEditor()), ), ), Column( children: getBoxList(context, boxModel.boxes), ), - mainModel.isCustomer() || _isNew - ? Container() - : ExpansionTile( - title: Text('For FCS'), - children: [ - widget.shipment != null - ? widget.shipment.status == 'Pending' - ? Padding( - padding: const EdgeInsets.only(left: 20.0), - child: fcsDropDown("Assigned", - MaterialCommunityIcons.worker), - ) - : Container() - : Container(), - Padding( - padding: EdgeInsets.only(left: 20), - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - padding: EdgeInsets.only(top: 8), - child: Text( - 'Attach Courier Shiping Labels', - style: TextStyle( - color: Colors.black, fontSize: 16), - ), - ), - Container( - padding: EdgeInsets.only(left: 10), - child: MultiImageFile( - enabled: true, - controller: multiImgController, - title: "Receipt File", - )), - ], - ), - ), - ], + Align( + alignment: Alignment.bottomCenter, + child: Center( + child: Container( + width: 250, + child: FlatButton( + child: Text('Create shipment'), + color: primaryColor, + textColor: Colors.white, + onPressed: () { + Navigator.pop(context); + }, ), - widget.shipment == null - ? Align( - alignment: Alignment.bottomCenter, - child: Center( - child: Container( - width: 250, - child: FlatButton( - child: Text('Create shipment'), - color: primaryColor, - textColor: Colors.white, - onPressed: () { - Navigator.pop(context); - }, - ), - ))) - : Container( - child: Column( - children: [ - widget.shipment.status == 'Confirmed' - ? Align( - alignment: Alignment.bottomCenter, - child: Center( - child: Container( - width: 250, - child: FlatButton( - child: Text('Complete Shipment'), - color: primaryColor, - textColor: Colors.white, - onPressed: () { - Navigator.pop(context); - }, - ), - ))) - : Align( - alignment: Alignment.bottomCenter, - child: Center( - child: Container( - width: 250, - child: FlatButton( - child: Text('Confirm Shipment'), - color: primaryColor, - textColor: Colors.white, - onPressed: () { - Navigator.pop(context); - }, - ), - ))), - Align( - alignment: Alignment.bottomCenter, - child: Center( - child: Container( - width: 250, - child: FlatButton( - child: Text('Cancel Shipment'), - color: Colors.grey[600], - textColor: Colors.white, - onPressed: () { - Navigator.pop(context); - }, - ), - ))) - ], - )) + ))) ], ), ), @@ -412,242 +247,14 @@ class _ShipmentEditorState extends State { ); } - Widget makeDropdown() { - ShipmentModel pickupModel = Provider.of(context); - - return Padding( - padding: const EdgeInsets.only(left: 5.0, right: 0), - child: Row( - children: [ - Padding( - padding: const EdgeInsets.only(left: 0, right: 10), - child: Icon(SimpleLineIcons.direction, color: primaryColor), - ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(right: 18.0), - child: LocalText( - context, - "shipment.type", - color: Colors.black54, - fontSize: 16, - ), - ), - DropdownButton( - isDense: true, - value: selectedPickupType, - style: TextStyle(color: Colors.black, fontSize: 14), - underline: Container( - height: 1, - color: Colors.grey, - ), - onChanged: (String newValue) { - setState(() { - selectedPickupType = newValue; - }); - }, - isExpanded: true, - items: pickupModel.pickupTypes - .map>((String value) { - return DropdownMenuItem( - value: value, - child: Text(value ?? "", - overflow: TextOverflow.ellipsis, - style: TextStyle(color: primaryColor)), - ); - }).toList(), - ), - ], - ), - ), - ], - ), - ); - } - - Widget makeLocation(BuildContext context, DeliveryAddress deliveryAddress) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Expanded( - child: DisplayText( - labelTextKey: "shipment.location", - iconData: MaterialCommunityIcons.truck_fast, - ), - ), - Chip( - label: InkWell( - onTap: () async { - DeliveryAddress d = await Navigator.push( - context, - BottomUpPageRoute(DeliveryAddressList( - forSelection: true, - )), - ); - setState(() { - this._pickupAddress = d; - }); - }, - child: LocalText(context, "delivery_address.change_address", - color: primaryColor), - )) - ], - ), - Padding( - padding: const EdgeInsets.only(left: 28.0), - child: deliveryAddress == null - ? Container() - : DeliveryAddressRow( - key: ValueKey(deliveryAddress.id), - deliveryAddress: deliveryAddress), - ), - ], - ); - } - List getBoxList(BuildContext context, List boxes) { - List _boxes = [boxes[0], boxes[1]]; - - return _boxes.asMap().entries.map((_box) { - DeliveryAddress shippingAddress = _box.value.shippingAddress; - + return boxes.asMap().entries.map((_box) { return InkWell( onTap: () { Navigator.of(context) - .push(BottomUpPageRoute(PickupBoxEditor(box: _box.value))); + .push(BottomUpPageRoute(ShipmentBoxEditor(box: _box.value))); }, - child: Container( - padding: EdgeInsets.only(left: 10), - child: Column( - children: [ - Row( - children: [ - Expanded( - child: new Padding( - padding: const EdgeInsets.symmetric(vertical: 10.0), - child: new Row( - children: [ - new Expanded( - child: new Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - shippingAddress.fullName == null - ? '' - : shippingAddress.fullName, - style: new TextStyle( - fontSize: 15.0, - color: Colors.black, - fontWeight: FontWeight.bold), - ), - ), - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - shippingAddress.addressLine1 == null - ? '' - : shippingAddress.addressLine1, - style: new TextStyle( - fontSize: 14.0, color: Colors.grey), - ), - ), - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - shippingAddress.addressLine2 == null - ? '' - : shippingAddress.addressLine2, - style: new TextStyle( - fontSize: 14.0, color: Colors.grey), - ), - ), - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - shippingAddress.city == null - ? '' - : shippingAddress.city, - style: new TextStyle( - fontSize: 14.0, color: Colors.grey), - ), - ), - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - shippingAddress.state == null - ? '' - : shippingAddress.state, - style: new TextStyle( - fontSize: 14.0, color: Colors.grey), - ), - ), - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - shippingAddress.phoneNumber == null - ? '' - : "Phone:${shippingAddress.phoneNumber}", - style: new TextStyle( - fontSize: 14.0, color: Colors.grey), - ), - ), - ], - ), - ), - ], - ), - ), - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - "L${_box.value.length}xW${_box.value.weight}xH${_box.value.height}", - style: new TextStyle( - fontSize: 15.0, color: Colors.black), - ), - ), - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - _box.value.weight == null - ? '' - : "Actual Weight:${_box.value.weight.toString()}lb", - style: - new TextStyle(fontSize: 14.0, color: Colors.grey), - ), - ), - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - _box.value.shipmentWeight == null - ? '' - : "Shipment Weight:${_box.value.shipmentWeight.toString()}lb", - style: - new TextStyle(fontSize: 14.0, color: Colors.grey), - ), - ), - ], - ) - ], - ), - _box.key == _boxes.length - 1 - ? Container() - : Divider( - color: Colors.black, - ) - ], - ), - ), + child: BoxRow(box: _box.value), ); }).toList(); } diff --git a/lib/pages/shipment/shipment_list.dart b/lib/pages/shipment/shipment_list.dart index 949f046..60d8bae 100644 --- a/lib/pages/shipment/shipment_list.dart +++ b/lib/pages/shipment/shipment_list.dart @@ -57,16 +57,6 @@ class _ShipmentListState extends State { // onPressed: () => showPlacesSearch(context), ), ], - // bottom: TabBar( - // unselectedLabelColor: Colors.grey, - // tabs: [ - // Tab( - // text: "Upcoming", - // ), - // Tab(text: "Completed"), - // Tab(text: "Canceled"), - // ], - // ), ), floatingActionButton: FloatingActionButton.extended( onPressed: () { @@ -87,14 +77,6 @@ class _ShipmentListState extends State { itemBuilder: (BuildContext context, int index) { return ShipmentListRow(pickUp: pickupModel.pickups[index]); }), - // body: TabBarView( - // children: [ - // //Icon(Icons.directions_car), - // _upComing(), - // _completed(), - // _canceled() - // ], - // ) ), ), ); @@ -103,67 +85,4 @@ class _ShipmentListState extends State { _newPickup() { Navigator.of(context).push(BottomUpPageRoute(ShipmentEditor())); } - - Widget _upComing() { - var pickupModel = Provider.of(context); - return Column( - children: [ - Expanded( - child: new ListView.separated( - separatorBuilder: (context, index) => Divider( - color: Colors.black, - ), - scrollDirection: Axis.vertical, - padding: EdgeInsets.only(top: 15), - shrinkWrap: true, - itemCount: pickupModel.upcoming.length, - itemBuilder: (BuildContext context, int index) { - return ShipmentListRow(pickUp: pickupModel.upcoming[index]); - }), - ), - ], - ); - } - - Widget _completed() { - var pickupModel = Provider.of(context); - return Column( - children: [ - Expanded( - child: new ListView.separated( - separatorBuilder: (context, index) => Divider( - color: Colors.black, - ), - scrollDirection: Axis.vertical, - padding: EdgeInsets.only(top: 15), - shrinkWrap: true, - itemCount: pickupModel.completed.length, - itemBuilder: (BuildContext context, int index) { - return ShipmentListRow(pickUp: pickupModel.completed[index]); - }), - ), - ], - ); - } - - Widget _canceled() { - var pickupModel = Provider.of(context); - return Column( - children: [ - Expanded( - child: new ListView.separated( - separatorBuilder: (context, index) => Divider( - color: Colors.black, - ), - scrollDirection: Axis.vertical, - padding: EdgeInsets.only(top: 15), - shrinkWrap: true, - itemCount: pickupModel.canceled.length, - itemBuilder: (BuildContext context, int index) { - return ShipmentListRow(pickUp: pickupModel.canceled[index]); - }), - ), - ], - ); - } } diff --git a/lib/pages/widgets/callbacks.dart b/lib/pages/widgets/callbacks.dart new file mode 100644 index 0000000..e5e9672 --- /dev/null +++ b/lib/pages/widgets/callbacks.dart @@ -0,0 +1,2 @@ +typedef OnTap(); +typedef CallBack = void Function(); diff --git a/lib/pages/widgets/defalut_delivery_address.dart b/lib/pages/widgets/defalut_delivery_address.dart new file mode 100644 index 0000000..143d91f --- /dev/null +++ b/lib/pages/widgets/defalut_delivery_address.dart @@ -0,0 +1,56 @@ +import 'package:fcs/domain/vo/delivery_address.dart'; +import 'package:fcs/helpers/theme.dart'; +import 'package:fcs/pages/delivery_address/delivery_address_row.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_icons/flutter_icons.dart'; + +import 'callbacks.dart'; +import 'display_text.dart'; +import 'local_text.dart'; + +class DefaultDeliveryAddress extends StatelessWidget { + final DeliveryAddress deliveryAddress; + final String labelKey; + final OnTap onTap; + + const DefaultDeliveryAddress( + {Key key, this.deliveryAddress, this.onTap, this.labelKey}) + : super(key: key); + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Expanded( + child: DisplayText( + labelTextKey: this.labelKey ?? "delivery_address", + iconData: MaterialCommunityIcons.truck_fast, + ), + ), + onTap == null + ? Container() + : GestureDetector( + onTap: () => onTap(), + child: Chip( + label: LocalText( + context, "delivery_address.change_address", + color: primaryColor)), + ) + ], + ), + Padding( + padding: const EdgeInsets.only(left: 28.0), + child: deliveryAddress == null + ? Container() + : DeliveryAddressRow( + key: ValueKey(deliveryAddress.id), + deliveryAddress: deliveryAddress), + ), + ], + ); + } +} diff --git a/lib/pages/widgets/delivery_address_selection.dart b/lib/pages/widgets/delivery_address_selection.dart new file mode 100644 index 0000000..54cd4cc --- /dev/null +++ b/lib/pages/widgets/delivery_address_selection.dart @@ -0,0 +1,85 @@ +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/delivery_address/delivery_address_row.dart'; +import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart'; +import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; +import 'package:fcs/pages/widgets/local_text.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class DeliveryAddressSelection extends StatelessWidget { + final DeliveryAddress deliveryAddress; + + const DeliveryAddressSelection({Key key, this.deliveryAddress}) + : super(key: key); + + @override + Widget build(BuildContext context) { + var shipmentModel = Provider.of(context); + + return Scaffold( + appBar: AppBar( + centerTitle: true, + leading: new IconButton( + icon: new Icon(Icons.close), + onPressed: () => Navigator.pop(context), + ), + backgroundColor: primaryColor, + title: LocalText( + context, + "delivery_addresses", + fontSize: 20, + color: Colors.white, + ), + ), + floatingActionButton: FloatingActionButton.extended( + onPressed: () { + Navigator.of(context) + .push(BottomUpPageRoute(DeliveryAddressEditor())); + }, + icon: Icon(Icons.add), + label: LocalText(context, "delivery_address.new_address", + color: Colors.white), + backgroundColor: primaryColor, + ), + body: Padding( + padding: const EdgeInsets.all(8.0), + child: ListView.separated( + separatorBuilder: (c, i) => Divider( + color: primaryColor, + ), + itemCount: shipmentModel.deliveryAddresses.length, + itemBuilder: (context, index) { + return _row(context, shipmentModel.deliveryAddresses[index]); + }), + )); + } + + _row(BuildContext context, DeliveryAddress _deliveryAddress) { + return InkWell( + onTap: () => _select(context, _deliveryAddress), + child: Row( + children: [ + Padding( + padding: const EdgeInsets.all(10.0), + child: Icon(Icons.check, + color: deliveryAddress != null && + _deliveryAddress.id == deliveryAddress.id + ? primaryColor + : Colors.black26), + ), + Expanded( + child: DeliveryAddressRow( + key: ValueKey(_deliveryAddress.id), + deliveryAddress: _deliveryAddress, + )), + ], + ), + ); + } + + _select(BuildContext context, DeliveryAddress _deliveryAddress) { + Navigator.pop(context, _deliveryAddress); + } +} diff --git a/lib/pages/widgets/fcs_expansion_tile.dart b/lib/pages/widgets/fcs_expansion_tile.dart index 1a5a8fb..f74365e 100644 --- a/lib/pages/widgets/fcs_expansion_tile.dart +++ b/lib/pages/widgets/fcs_expansion_tile.dart @@ -2,7 +2,7 @@ import 'package:fcs/helpers/theme.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'multi_img_controller.dart'; +import 'callbacks.dart'; class FcsExpansionTile extends StatefulWidget { final ValueChanged onExpansionChanged; diff --git a/lib/pages/widgets/local_button.dart b/lib/pages/widgets/local_button.dart new file mode 100644 index 0000000..d37e4ed --- /dev/null +++ b/lib/pages/widgets/local_button.dart @@ -0,0 +1,56 @@ +import 'package:fcs/helpers/theme.dart'; +import 'package:fcs/pages/widgets/local_text.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import 'callbacks.dart'; + +class LocalButton extends StatelessWidget { + final CallBack callBack; + final IconData iconData; + final String textKey; + + const LocalButton({Key key, this.callBack, this.iconData, this.textKey}) + : super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + padding: EdgeInsets.only(left: 10, right: 10, top: 10), + child: Container( + height: 45.0, + decoration: BoxDecoration( + color: primaryColor, + shape: BoxShape.rectangle, + ), + child: ButtonTheme( + minWidth: 900.0, + height: 100.0, + child: FlatButton( + onPressed: callBack == null ? null : () => callBack(), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + iconData == null + ? Container() + : Icon( + iconData, + color: Colors.white, + ), + SizedBox( + width: 15, + ), + LocalText( + context, + textKey, + color: Colors.white, + fontSize: 16, + ), + ], + ), + ), + ), + ), + ); + } +} diff --git a/lib/pages/widgets/local_dropdown.dart b/lib/pages/widgets/local_dropdown.dart new file mode 100644 index 0000000..5e74dec --- /dev/null +++ b/lib/pages/widgets/local_dropdown.dart @@ -0,0 +1,68 @@ +import 'package:fcs/helpers/theme.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import 'local_text.dart'; + +class LocalDropdown extends StatelessWidget { + final Function(T) callback; + final IconData iconData; + final T selectedValue; + final List values; + + const LocalDropdown( + {Key key, this.callback, this.iconData, this.selectedValue, this.values}) + : super(key: key); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.only(left: 5.0, right: 0), + child: Row( + children: [ + Padding( + padding: const EdgeInsets.only(left: 0, right: 10), + child: Icon(iconData, color: primaryColor), + ), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.only(right: 18.0), + child: LocalText( + context, + "shipment.type", + color: Colors.black54, + fontSize: 16, + ), + ), + DropdownButton( + isDense: true, + value: selectedValue, + style: TextStyle(color: Colors.black, fontSize: 14), + underline: Container( + height: 1, + color: Colors.grey, + ), + onChanged: (T newValue) { + callback(newValue); + }, + isExpanded: true, + items: values.map>((T value) { + return DropdownMenuItem( + value: value, + child: Text(value==null? "":value.toString(), + overflow: TextOverflow.ellipsis, + style: TextStyle(color: primaryColor)), + ); + }).toList(), + ), + ], + ), + ), + ], + ), + ); + } +} diff --git a/lib/pages/widgets/multi_img_controller.dart b/lib/pages/widgets/multi_img_controller.dart index 5eb33e3..ee75035 100644 --- a/lib/pages/widgets/multi_img_controller.dart +++ b/lib/pages/widgets/multi_img_controller.dart @@ -1,9 +1,8 @@ import 'dart:io'; +import 'callbacks.dart'; import 'display_image_source.dart'; -typedef CallBack = void Function(); - class MultiImgController { List imageUrls; List addedFiles = []; diff --git a/lib/pages/widgets/title_with_add_button.dart b/lib/pages/widgets/title_with_add_button.dart new file mode 100644 index 0000000..79607f1 --- /dev/null +++ b/lib/pages/widgets/title_with_add_button.dart @@ -0,0 +1,52 @@ +import 'package:fcs/helpers/theme.dart'; +import 'package:fcs/pages/widgets/local_text.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import 'callbacks.dart'; + +class TitleWithAddButton extends StatelessWidget { + final IconData iconData; + final String titleKey; + final OnTap onTap; + + const TitleWithAddButton({Key key, this.iconData, this.titleKey, this.onTap}) + : super(key: key); + + @override + Widget build(BuildContext context) { + return Row( + children: [ + Row( + children: [ + Padding( + padding: const EdgeInsets.only(right: 15.0), + child: Icon( + this.iconData, + color: primaryColor, + ), + ), + LocalText( + context, + titleKey, + color: Colors.black54, + fontSize: 20, + ) + ], + ), + Spacer(), + onTap == null + ? Container() + : Padding( + padding: const EdgeInsets.only(right: 25.0), + child: IconButton( + onPressed: () => onTap(), + icon: Icon( + Icons.add_circle, + color: primaryColor, + )), + ) + ], + ); + } +}