diff --git a/lib/pages/carton/cargo_table.dart b/lib/pages/carton/cargo_table.dart deleted file mode 100644 index ea21a8f..0000000 --- a/lib/pages/carton/cargo_table.dart +++ /dev/null @@ -1,118 +0,0 @@ -import 'package:fcs/domain/entities/cargo_type.dart'; -import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/widgets/local_text.dart'; -import 'package:flutter/material.dart'; - -class CargoTable extends StatefulWidget { - final List? cargoTypes; - - const CargoTable({ - Key? key, - this.cargoTypes, - }) : super(key: key); - - @override - _CargoTableState createState() => _CargoTableState(); -} - -class _CargoTableState extends State { - @override - Widget build(BuildContext context) { - return SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: DataTable( - headingRowHeight: 40, - columnSpacing: 50, - showCheckboxColumn: false, - decoration: BoxDecoration(border: Border.all(color: Colors.white)), - border: TableBorder(horizontalInside: BorderSide(color: Colors.white)), - columns: [ - DataColumn( - label: LocalText( - context, - "cargo.type", - color: Colors.grey, - ), - ), - DataColumn( - label: LocalText( - context, - "cargo.qty", - color: Colors.grey, - ), - ), - DataColumn( - label: LocalText( - context, - "cargo.weight", - color: Colors.grey, - ), - ), - ], - rows: getCargoRows(context), - ), - ); - } - - List getCargoRows(BuildContext context) { - if (widget.cargoTypes == null) { - return []; - } - double total = 0; - var rows = widget.cargoTypes!.map((c) { - total += c.weight; - return DataRow( - onSelectChanged: (bool? selected) async {}, - cells: [ - DataCell(new Text( - c.name ?? "", - style: textStyle, - )), - DataCell(c.qty == 0 - ? Center( - child: Text( - "-", - style: textStyle, - ), - ) - : Center( - child: Text( - c.qty.toString(), - style: textStyle, - ), - )), - DataCell( - Text(c.weight.toStringAsFixed(2), style: textStyle), - ), - ], - ); - }).toList(); - - var totalRow = DataRow( - onSelectChanged: (bool? selected) {}, - cells: [ - DataCell(Align( - alignment: Alignment.centerRight, - child: LocalText( - context, - "shipment.cargo.total", - color: Colors.black87, - fontWeight: FontWeight.bold, - ), - )), - DataCell(Text("")), - DataCell( - Padding( - padding: const EdgeInsets.only(right: 48.0), - child: Align( - alignment: Alignment.centerRight, - child: Text(total.toStringAsFixed(2)+" lb", - style: TextStyle(fontWeight: FontWeight.bold))), - ), - ), - ], - ); - rows.add(totalRow); - return rows; - } -} diff --git a/lib/pages/carton/cargo_type_addtion.dart b/lib/pages/carton/cargo_type_addtion.dart deleted file mode 100644 index eb11f1e..0000000 --- a/lib/pages/carton/cargo_type_addtion.dart +++ /dev/null @@ -1,132 +0,0 @@ -import 'package:fcs/domain/entities/cargo_type.dart'; -import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/main/util.dart'; -import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; -import 'package:fcs/pages/widgets/local_app_bar.dart'; -import 'package:fcs/pages/widgets/local_title.dart'; -import 'package:fcs/pages/widgets/progress.dart'; -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; - -class CargoTypeAddition extends StatefulWidget { - @override - _CargoTypeAdditionState createState() => _CargoTypeAdditionState(); -} - -class _CargoTypeAdditionState extends State { - bool _isLoading = false; - - List cargos = []; - List specialCargos = []; - - @override - void initState() { - super.initState(); - var shipmentRateModel = - Provider.of(context, listen: false); - - cargos = shipmentRateModel.rate.cargoTypes.map((e) => e.clone()).toList(); - specialCargos = List.from(shipmentRateModel.rate.customDuties); - specialCargos = - shipmentRateModel.rate.customDuties.map((e) => e.clone()).toList(); - - cargos.forEach((p) { - p.isChecked = false; - p.isCutomDuty = false; - p.weight = 0; - p.qty = 0; - }); - specialCargos.forEach((p) { - p.isChecked = false; - p.isCutomDuty = true; - p.weight = 0; - p.qty = 1; - }); - } - - @override - void dispose() { - super.dispose(); - } - - @override - Widget build(BuildContext context) { - List getCargoRowList(List _c) { - return _c.map((c) { - return Container( - child: Container( - padding: - EdgeInsets.only(left: 10.0, right: 5.0, top: 3.0, bottom: 3.0), - child: InkWell( - onTap: () { - setState(() { - c.isChecked = !c.isChecked; - }); - }, - child: Row( - children: [ - Checkbox( - value: c.isChecked, - activeColor: primaryColor, - onChanged: (bool? check) { - setState(() { - c.isChecked = check ?? false; - }); - }), - new Text(c.name ?? '', style: textStyle), - ], - ), - ), - ), - ); - }).toList(); - } - - final saveBtn = fcsButton( - context, - getLocalString(context, 'box.cargo.select.btn'), - callack: () { - List _cargos = - this.cargos.where((c) => c.isChecked).toList(); - List _scargos = - this.specialCargos.where((c) => c.isChecked).toList(); - _cargos.addAll(_scargos); - Navigator.pop(context, _cargos); - }, - ); - - return LocalProgress( - inAsyncCall: _isLoading, - child: Scaffold( - appBar: LocalAppBar( - labelKey: 'cargo.form.title', - backgroundColor: Colors.white, - labelColor: primaryColor, - arrowColor: primaryColor), - body: Container( - padding: EdgeInsets.all(8), - child: ListView( - shrinkWrap: true, - children: [ - LocalTitle( - textKey: "box.select.cargo.title", - ), - Column( - children: getCargoRowList(cargos), - ), - LocalTitle( - textKey: "box.select.cargo.title", - ), - Column( - children: getCargoRowList(specialCargos), - ), - SizedBox(height: 30), - saveBtn, - SizedBox(height: 20), - ], - ), - ), - ), - ); - } -} diff --git a/lib/pages/carton/carton_cargo_table.dart b/lib/pages/carton/carton_cargo_table.dart deleted file mode 100644 index db8fe82..0000000 --- a/lib/pages/carton/carton_cargo_table.dart +++ /dev/null @@ -1,260 +0,0 @@ -import 'package:fcs/domain/entities/cargo_type.dart'; -import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/main/util.dart'; -import 'package:fcs/pages/widgets/dialog_input.dart'; -import 'package:fcs/pages/widgets/local_text.dart'; -import 'package:flutter/material.dart'; - -typedef OnRemove(CargoType cargoType); -typedef OnUpdate(CargoType cargoType); - -class CargoTable extends StatefulWidget { - final List? cargoTypes; - final bool? isNew; - final OnRemove? onRemove; - final OnUpdate? onUpdate; - - const CargoTable( - {Key? key, this.cargoTypes, this.isNew, this.onRemove, this.onUpdate}) - : super(key: key); - - @override - _CargoTableState createState() => _CargoTableState(); -} - -class _CargoTableState extends State { - double totalWeight = 0; - List? cargoTypes; - - @override - void initState() { - cargoTypes = widget.cargoTypes; - if (!widget.isNew!) { - totalWeight = - cargoTypes!.fold(0, (previous, current) => previous + current.weight); - } - - super.initState(); - } - - @override - Widget build(BuildContext context) { - return SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: DataTable( - showCheckboxColumn: false, - headingRowHeight: 40, - // columnSpacing: 40, - decoration: BoxDecoration(border: Border.all(color: Colors.white)), - border: TableBorder(horizontalInside: BorderSide(color: Colors.white)), - columns: [ - DataColumn( - label: LocalText( - context, - "cargo.type", - color: Colors.grey, - ), - ), - DataColumn( - label: LocalText( - context, - "cargo.qty", - color: Colors.grey, - ), - ), - DataColumn( - label: LocalText( - context, - "cargo.weight", - color: Colors.grey, - ), - ), - ], - rows: getCargoRows(context), - ), - ); - } - - List getCargoRows(BuildContext context) { - if (cargoTypes == null) { - return []; - } - var rows = cargoTypes!.map((c) { - return DataRow( - onSelectChanged: (bool? selected) async {}, - cells: [ - DataCell( - new Text( - c.name ?? '', - style: textStyle, - ), - ), - DataCell( - c.isCutomDuty - ? GestureDetector( - onTap: () async { - String? _t = await showDialog( - context: context, - builder: (_) => DialogInput( - label: "cargo.qty", value: c.qty.toString())); - - if (_t == null) return; - setState(() { - c.qty = int.tryParse(_t) ?? 0; - }); - if (widget.onUpdate != null) widget.onUpdate!(c); - }, - child: Center( - child: Container( - width: 40, - padding: const EdgeInsets.all(7.0), - decoration: BoxDecoration( - border: Border.all(color: primaryColor), - borderRadius: BorderRadius.all(Radius.circular(5.0)), - ), - child: new Text( - c.qty.toString(), - style: textStyle, - textAlign: TextAlign.center, - ), - ), - ), - ) - : Center( - child: new Text( - "-", - style: textStyle, - ), - ), - ), - DataCell( - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - GestureDetector( - onTap: () async { - if (this.totalWeight <= 0) { - showMsgDialog( - context, "Error", "Please insert total weight"); - return; - } - - String? _t = await showDialog( - context: context, - builder: (_) => DialogInput( - label: "cargo.weight", - value: c.weight.toStringAsFixed(2))); - - if (_t == null) return; - setState(() { - c.weight = double.tryParse(_t) ?? 0; - }); - if (c.weight != 0) { - _cal(); - } - if (widget.onUpdate != null) widget.onUpdate!(c); - }, - child: Container( - padding: const EdgeInsets.all(7.0), - decoration: BoxDecoration( - border: Border.all(color: primaryColor), - borderRadius: BorderRadius.all(Radius.circular(5.0)), - ), - child: Text(c.weight.toStringAsFixed(2), style: textStyle), - ), - ), - widget.onRemove == null - ? SizedBox( - width: 50, - ) - : IconButton( - icon: Icon( - Icons.remove_circle, - color: primaryColor, - ), - onPressed: () { - if (widget.onRemove != null) widget.onRemove!(c); - }) - ], - ), - ), - ], - ); - }).toList(); - - var totalRow = DataRow( - onSelectChanged: (bool? selected) {}, - cells: [ - DataCell(Align( - alignment: Alignment.centerRight, - child: LocalText( - context, - "shipment.cargo.total", - color: Colors.black87, - fontWeight: FontWeight.bold, - ), - )), - DataCell(Text("")), - DataCell( - Padding( - padding: const EdgeInsets.only(right: 48.0), - child: Align( - alignment: Alignment.centerRight, - child: InkWell( - onTap: () async { - String? _t = await showDialog( - context: context, - builder: (_) => DialogInput( - label: "shipment.cargo.total", - value: totalWeight.toStringAsFixed(2)), - ); - - if (_t == null) return; - setState(() { - totalWeight = double.tryParse(_t) ?? 0; - }); - _cal(); - }, - child: Container( - padding: const EdgeInsets.all(7.0), - decoration: BoxDecoration( - border: Border.all(color: primaryColor), - borderRadius: BorderRadius.all(Radius.circular(5.0)), - ), - child: Text(totalWeight.toStringAsFixed(2), - style: TextStyle(fontWeight: FontWeight.bold)), - ), - )), - ), - ), - ], - ); - rows.add(totalRow); - return rows; - } - - _cal() { - var cargoType = autoCalWeight(cargoTypes!, totalWeight); - if (cargoType == null) return; - - setState(() { - cargoTypes!.remove(cargoType); - cargoTypes!.add(cargoType); - }); - - if (widget.onUpdate != null) { - widget.onUpdate!(cargoType); - } - } -} - -CargoType? autoCalWeight(List cargoTypes, double total) { - List noWeight = cargoTypes.where((c) => c.weight == 0).toList(); - if (noWeight.length != 1) return null; - - double _existing = - cargoTypes.fold(0, (previous, current) => previous + current.weight); - - noWeight[0].weight = total - _existing; - return noWeight[0]; -} diff --git a/lib/pages/carton/carton_editor.dart b/lib/pages/carton/carton_editor.dart index 79799ef..8a34610 100644 --- a/lib/pages/carton/carton_editor.dart +++ b/lib/pages/carton/carton_editor.dart @@ -14,10 +14,10 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import '../main/util.dart'; -import 'carton_editor_for_package.dart'; +import 'carton_package_form.dart'; import 'carton_info.dart'; import 'mix_carton/mix_carton_form.dart'; -import 'carton_row.dart'; +import 'widget/carton_row.dart'; class CartonEditor extends StatefulWidget { final Carton? carton; @@ -154,7 +154,7 @@ class _CartonEditorState extends State { Navigator.push( context, CupertinoPageRoute( - builder: (context) => CartonEditorForPackage( + builder: (context) => CartonPackageForm( sender: _sender!, consignee: _consignee!, ))); diff --git a/lib/pages/carton/carton_filter.dart b/lib/pages/carton/carton_filter.dart index 27b687d..9fc0054 100644 --- a/lib/pages/carton/carton_filter.dart +++ b/lib/pages/carton/carton_filter.dart @@ -8,7 +8,7 @@ import '../../helpers/theme.dart'; import '../../localization/app_translations.dart'; import '../main/util.dart'; import '../widgets/local_text.dart'; -import 'user_search_result.dart'; +import 'widget/user_search_result.dart'; import 'model/carton_model.dart'; import 'model/consignee_selection_model.dart'; diff --git a/lib/pages/carton/carton_image_upload.dart b/lib/pages/carton/carton_image_upload_editor.dart similarity index 94% rename from lib/pages/carton/carton_image_upload.dart rename to lib/pages/carton/carton_image_upload_editor.dart index d2bf2f9..37b60c2 100644 --- a/lib/pages/carton/carton_image_upload.dart +++ b/lib/pages/carton/carton_image_upload_editor.dart @@ -9,14 +9,14 @@ import '../widgets/multi_img_file.dart'; typedef void FindCallBack(); -class CartonImageUpload extends StatefulWidget { +class CartonImageUploadEditor extends StatefulWidget { final Carton? box; - const CartonImageUpload({this.box}); + const CartonImageUploadEditor({this.box}); @override _CartonImageUploaState createState() => _CartonImageUploaState(); } -class _CartonImageUploaState extends State { +class _CartonImageUploaState extends State { bool _isLoading = false; Carton? _box; MultiImgController multiImgController = MultiImgController(); diff --git a/lib/pages/carton/carton_info.dart b/lib/pages/carton/carton_info.dart index 2d31edc..8cb50ca 100644 --- a/lib/pages/carton/carton_info.dart +++ b/lib/pages/carton/carton_info.dart @@ -3,7 +3,7 @@ import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/carton/carton_image_upload.dart'; +import 'package:fcs/pages/carton/carton_image_upload_editor.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/package/model/package_model.dart'; import 'package:fcs/pages/widgets/display_text.dart'; @@ -18,6 +18,7 @@ import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; import '../widgets/local_button.dart'; +import 'carton_package_editor.dart'; import 'mix_carton/mix_carton_editor.dart'; import 'model/carton_model.dart'; @@ -297,7 +298,7 @@ class _CartonInfoState extends State { Navigator.push( context, CupertinoPageRoute( - builder: (context) => CartonImageUpload(box: _carton)), + builder: (context) => CartonImageUploadEditor(box: _carton)), ); }, child: const Text('Upload Images'), @@ -404,28 +405,25 @@ class _CartonInfoState extends State { } _gotoEditor() async { - if (_carton.cartonType == carton_mix_carton) { - bool? updated = await Navigator.push( - context, - CupertinoPageRoute( - builder: (context) => MixCartonEditor(carton: _carton)), - ); + bool? updated = _carton.cartonType == carton_mix_carton + ? await Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => MixCartonEditor(carton: _carton)), + ) + : await Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => CartonPackageEditor(carton: _carton)), + ); + + if (updated ?? false) { + Carton? c = + await context.read().getCarton(widget.carton.id ?? ""); + if (c == null) return; + _carton = c; + _init(); } - // bool? updated = await Navigator.push( - // context, - // CupertinoPageRoute( - // builder: (context) => MixCartonEditor(carton: _carton)), - // ); - // if (updated ?? false) { - // // var cartonModel = Provider.of(context, listen: false); - // // var c = await cartonModel.getCarton(widget.box.id ?? ""); - // // setState(() { - // // _box = c; - // // _loadPackages(); - // // _loadMixCartons(); - // // _updateBoxData(); - // // }); - // } } _delete() { diff --git a/lib/pages/carton/carton_list.dart b/lib/pages/carton/carton_list.dart index 067133e..5a3a61d 100644 --- a/lib/pages/carton/carton_list.dart +++ b/lib/pages/carton/carton_list.dart @@ -17,7 +17,7 @@ import '../fcs_shipment/model/fcs_shipment_model.dart'; import 'carton_editor.dart'; import 'carton_filter.dart'; import 'carton_info.dart'; -import 'carton_list_row.dart'; +import 'widget/carton_list_row.dart'; class CartonList extends StatefulWidget { @override diff --git a/lib/pages/carton/carton_package_editor.dart b/lib/pages/carton/carton_package_editor.dart new file mode 100644 index 0000000..e0bf4e3 --- /dev/null +++ b/lib/pages/carton/carton_package_editor.dart @@ -0,0 +1,263 @@ +// ignore_for_file: deprecated_member_use + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; +import 'package:provider/provider.dart'; + +import '../../../domain/constants.dart'; +import '../../../domain/entities/carton_size.dart'; +import '../../../domain/entities/fcs_shipment.dart'; +import '../../../domain/vo/local_step.dart'; +import '../../../helpers/theme.dart'; +import '../../domain/entities/cargo_type.dart'; +import '../../domain/entities/carton.dart'; +import '../../domain/entities/package.dart'; +import '../../domain/entities/user.dart'; +import '../main/util.dart'; +import '../widgets/local_text.dart'; +import '../widgets/progress.dart'; +import '../widgets/step_widget.dart'; +import 'cargo_widget.dart'; +import 'carton_size_widget.dart'; +import 'carton_submit.dart'; +import 'model/package_selection_model.dart'; +import 'package_selection_widget.dart'; + +class CartonPackageEditor extends StatefulWidget { + final Carton carton; + + const CartonPackageEditor({Key? key, required this.carton}) : super(key: key); + + @override + State createState() => _CartonPackageEditorState(); +} + +class _CartonPackageEditorState extends State { + var dateFormatter = DateFormat('dd MMM yyyy'); + final NumberFormat numberFormatter = NumberFormat("#,###"); + List steps = [ + LocalStep(lable: 'Size', stepType: StepType.SIZE), + LocalStep(lable: 'Packages', stepType: StepType.PACKAGES), + LocalStep(lable: 'Cargos', stepType: StepType.CARGOS), + LocalStep(lable: 'Submit', stepType: StepType.SUBMIT) + ]; + List _packages = []; + List _cargoTypes = []; + List _surchareItems = []; + + int currentStep = 0; + double _length = 0; + double _width = 0; + double _height = 0; + + String _selectedDeliveryType = delivery_caton; + String _billToValue = billToSender; + + FcsShipment? _shipment; + String _cartonSizeType = standardCarton; + CartonSize? _standardSize; + bool _isLoading = false; + + User? _consignee; + User? _sender; + + @override + void initState() { + _sender = User( + name: "ptd-phyo44 kaelone", + fcsID: "FCS-8X6V", + phoneNumber: "+959444444444", + id: "48u_4s-HiQeW-HwSqeRd9TSMWh3mLZfSk5rpaUEh_zw"); + + _consignee = User( + id: "HsIwG88K-0_HSazgEy5QR27kcjkOvfv7_Sr1JP18Q1A", + name: "One One", + phoneNumber: "+959111111111", + fcsID: "FCS-EFRF"); + + context.read().clearSelection(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return WillPopScope( + onWillPop: () { + if (currentStep == 0) { + Navigator.of(context).pop(); + } + if (currentStep > 0) { + setState(() { + currentStep -= 1; + }); + } + + return Future.value(false); + }, + child: LocalProgress( + inAsyncCall: _isLoading, + child: Scaffold( + appBar: AppBar( + elevation: 0, + centerTitle: true, + leading: IconButton( + icon: const Icon(CupertinoIcons.back, + color: primaryColor, size: 25), + onPressed: () { + if (currentStep == 0) { + Navigator.of(context).pop(); + } + if (currentStep > 0) { + setState(() { + currentStep -= 1; + }); + } + }, + ), + backgroundColor: Colors.white, + title: LocalText(context, 'boxes.new', + color: primaryColor, fontSize: 20), + ), + body: Column( + children: [ + StepperWidget( + labels: steps.map((e) => e.lable).toList(), + currentStep: currentStep, + eachStepWidth: MediaQuery.of(context).size.width / 4, + onChange: (index) { + if (index > currentStep) { + return; + } + setState(() { + currentStep = index; + }); + }, + ), + getContent(currentStep) + ], + ))), + ); + } + + Widget getContent(int index) { + var step = steps[index]; + if (step.stepType == StepType.SIZE) { + return Expanded( + child: CartonSizeWidget( + deliveryType: _selectedDeliveryType, + billType: _billToValue, + sender: _sender!, + consignee: _consignee!, + shipment: _shipment, + cartonSizeType: _cartonSizeType, + standardSize: _standardSize, + length: _length, + width: _width, + height: _height, + onPrevious: () { + Navigator.pop(context); + }, + onContinue: (deliveryType, billType, shipment, cartonSizeType, + {standardSize, length, width, height}) { + setState(() { + _selectedDeliveryType = deliveryType; + _billToValue = billType; + _shipment = shipment; + _cartonSizeType = cartonSizeType; + _standardSize = standardSize; + _length = length ?? 0; + _width = width ?? 0; + _height = height ?? 0; + currentStep += 1; + }); + }, + )); + } else if (step.stepType == StepType.PACKAGES) { + return Expanded( + child: PackageSelectionWidget( + sender: _sender!, + consignee: _consignee!, + shipment: _shipment!, + packages: _packages, + onContinue: (packages) { + setState(() { + _packages = List.from(packages); + currentStep += 1; + }); + }, + onPrevious: (packages) { + setState(() { + _packages = List.from(packages); + currentStep -= 1; + }); + }, + ), + ); + } else if (step.stepType == StepType.CARGOS) { + return Expanded( + child: CargoWidget( + sender: _sender!, + consignee: _consignee!, + cargoTypes: _cargoTypes, + surchargeItems: _surchareItems, + onContinue: (cargoTypes, customDuties) { + setState(() { + _cargoTypes = List.from(cargoTypes); + _surchareItems = List.from(customDuties); + currentStep += 1; + }); + }, + onPrevious: (cargoTypes, customDuties) { + setState(() { + _cargoTypes = List.from(cargoTypes); + _surchareItems = List.from(customDuties); + currentStep -= 1; + }); + }, + ), + ); + } else { + return Expanded( + child: CartonSubmit( + sender: _sender!, + consingee: _consignee!, + billToValue: _billToValue, + cartonSizeType: _cartonSizeType, + standardSize: _standardSize, + length: _length, + width: _width, + height: _height, + deliveryType: _selectedDeliveryType, + shipment: _shipment!, + packages: _packages, + cargoTypes: _cargoTypes, + surchareItems: _surchareItems, + onCreate: () { + _create(); + }, + onPrevious: () { + setState(() { + currentStep -= 1; + }); + }, + ), + ); + } + } + + _create() async { + setState(() { + _isLoading = true; + }); + try { + Navigator.pop(context, true); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + setState(() { + _isLoading = false; + }); + } + } +} diff --git a/lib/pages/carton/carton_editor_for_package.dart b/lib/pages/carton/carton_package_form.dart similarity index 96% rename from lib/pages/carton/carton_editor_for_package.dart rename to lib/pages/carton/carton_package_form.dart index 7f6be13..3f627c8 100644 --- a/lib/pages/carton/carton_editor_for_package.dart +++ b/lib/pages/carton/carton_package_form.dart @@ -23,11 +23,11 @@ import 'carton_submit.dart'; import 'model/package_selection_model.dart'; import 'package_selection_widget.dart'; -class CartonEditorForPackage extends StatefulWidget { +class CartonPackageForm extends StatefulWidget { final User sender; final User consignee; - const CartonEditorForPackage( + const CartonPackageForm( {Key? key, required this.sender, required this.consignee, @@ -35,10 +35,10 @@ class CartonEditorForPackage extends StatefulWidget { : super(key: key); @override - State createState() => _CartonEditorForPackageState(); + State createState() => _CartonPackageFormState(); } -class _CartonEditorForPackageState extends State { +class _CartonPackageFormState extends State { var dateFormatter = DateFormat('dd MMM yyyy'); final NumberFormat numberFormatter = NumberFormat("#,###"); List steps = [ diff --git a/lib/pages/carton/package_carton_form.dart b/lib/pages/carton/package_carton_form.dart deleted file mode 100644 index a89a528..0000000 --- a/lib/pages/carton/package_carton_form.dart +++ /dev/null @@ -1,365 +0,0 @@ -import 'package:fcs/domain/constants.dart'; -import 'package:fcs/domain/entities/carton.dart'; -import 'package:fcs/domain/entities/cargo_type.dart'; -import 'package:fcs/domain/entities/carton_size.dart'; -import 'package:fcs/domain/entities/package.dart'; -import 'package:fcs/domain/entities/user.dart'; -import 'package:fcs/domain/vo/delivery_address.dart'; -import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/carton_size/carton_size_list.dart'; -import 'package:fcs/pages/carton_size/model/carton_size_model.dart'; -import 'package:fcs/pages/main/util.dart'; -import 'package:fcs/pages/widgets/defalut_delivery_address.dart'; -import 'package:fcs/pages/widgets/delivery_address_selection.dart'; -import 'package:fcs/pages/widgets/length_picker.dart'; -import 'package:fcs/pages/widgets/local_button.dart'; -import 'package:fcs/pages/widgets/local_text.dart'; -import 'package:fcs/pages/widgets/local_title.dart'; -import 'package:fcs/pages/widgets/progress.dart'; -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_vector_icons/flutter_vector_icons.dart'; -import 'package:provider/provider.dart'; - -import 'cargo_type_addtion.dart'; -import 'carton_cargo_table.dart'; -import 'model/carton_model.dart'; - -class PackageCartonForm extends StatefulWidget { - final Carton? carton; - final bool? isNew; - final User? consignee; - PackageCartonForm({this.carton, this.isNew, this.consignee}); - - @override - _PackageCartonFormState createState() => _PackageCartonFormState(); -} - -class _PackageCartonFormState extends State { - TextEditingController _lengthCtl = new TextEditingController(); - TextEditingController _widthCtl = new TextEditingController(); - TextEditingController _heightCtl = new TextEditingController(); - - Carton? _carton; - bool _isLoading = false; - DeliveryAddress? _deliveryAddress = new DeliveryAddress(); - List _cargoTypes = []; - CartonSize? selectedCatonSize; - bool isFromPackages = false; - bool isFromCartons = false; - - @override - void initState() { - super.initState(); - _load(); - } - - _load() { - _carton = widget.carton; - isFromPackages = _carton!.cartonType == carton_from_packages; - isFromCartons = _carton!.cartonType == carton_from_cartons; - - if (widget.isNew!) { - _lengthCtl.text = "0"; - _widthCtl.text = "0"; - _heightCtl.text = "0"; - } else { - _cargoTypes = widget.carton!.cargoTypes.map((e) => e.clone()).toList(); - _lengthCtl.text = _carton!.length.toString(); - _widthCtl.text = _carton!.width.toString(); - _heightCtl.text = _carton!.height.toString(); - _deliveryAddress = _carton!.deliveryAddress; - _getCartonSize(); - } - } - - _getCartonSize() { - var cartonSizeModel = Provider.of(context, listen: false); - cartonSizeModel.cartonSizes.forEach((c) { - if (c.length == _carton!.length && - c.width == _carton!.width && - c.height == _carton!.height) { - selectedCatonSize = CartonSize( - id: c.id, - name: c.name, - length: c.length, - width: c.width, - height: c.height); - } - }); - } - - @override - Widget build(BuildContext context) { - final lengthBox = LengthPicker( - controller: _lengthCtl, - lableKey: "box.length", - isReadOnly: false, - ); - final widthBox = LengthPicker( - controller: _widthCtl, - lableKey: "box.width", - isReadOnly: false, - ); - final heightBox = LengthPicker( - controller: _heightCtl, - lableKey: "box.height", - isReadOnly: false, - ); - final dimBox = Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(right: 8.0), - child: Icon(FontAwesome.arrow_circle_right, color: primaryColor), - ), - SizedBox(child: lengthBox, width: 80), - SizedBox(child: widthBox, width: 80), - SizedBox(child: heightBox, width: 80), - ], - ); - final createBtn = LocalButton( - textKey: widget.isNew! ? "box.new_carton_btn" : "box.cargo.save.btn", - callBack: _creatCarton, - ); - - final cargoTableTitleBox = LocalTitle( - textKey: "box.cargo.type", - trailing: IconButton( - icon: Icon( - Icons.add_circle, - color: primaryColor, - ), - onPressed: () async { - List? cargos = await Navigator.push>( - context, - CupertinoPageRoute(builder: (context) => CargoTypeAddition())); - if (cargos == null) return; - setState(() { - _cargoTypes.addAll( - cargos.where((e) => !_cargoTypes.contains(e)).toList()); - }); - }), - ); - - final cargoTableBox = CargoTable( - isNew: widget.isNew, - cargoTypes: _cargoTypes, - onRemove: (c) => _removeCargo(c), - onUpdate: (c) => _updateCargo(c), - ); - - 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()), - shadowColor: Colors.transparent, - backgroundColor: Colors.white, - title: LocalText( - context, - widget.isNew! ? "boxes.create.title" : "box.edit.title", - fontSize: 20, - color: primaryColor, - ), - ), - body: Padding( - padding: const EdgeInsets.all(8.0), - child: ListView( - children: [ - cargoTableTitleBox, - cargoTableBox, - LocalTitle(textKey: "box.dimension"), - cartonSizeDropdown(), - dimBox, - LocalTitle(textKey: "box.delivery_address"), - DefaultDeliveryAddress( - deliveryAddress: _deliveryAddress, - labelKey: "box.delivery_address", - onTap: () async { - DeliveryAddress? d = await Navigator.push( - context, - CupertinoPageRoute( - builder: (context) => DeliveryAddressSelection( - deliveryAddress: _deliveryAddress, - user: User( - id: _carton!.userID, - name: _carton!.userName), - )), - ); - if (d == null) return; - setState(() { - _deliveryAddress = d; - }); - }), - SizedBox( - height: 20, - ), - createBtn - ], - ), - ), - ), - ); - } - - Widget cartonSizeDropdown() { - List _cartonSizes = - Provider.of(context).getCartonSizes; - - return Padding( - padding: const EdgeInsets.only(top: 10), - child: Row( - children: [ - Padding( - padding: const EdgeInsets.only(left: 0, right: 10), - child: Icon(AntDesign.CodeSandbox, color: primaryColor), - ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(right: 18.0), - child: LocalText( - context, - "box.carton_size", - color: Colors.black54, - fontSize: 16, - ), - ), - DropdownButton( - isDense: true, - value: selectedCatonSize, - style: TextStyle(color: Colors.black, fontSize: 14), - underline: Container( - height: 1, - color: Colors.grey, - ), - onChanged: (CartonSize? newValue) { - setState(() { - if (newValue!.name == MANAGE_CARTONSIZE) { - selectedCatonSize = null; - _manageCartonSize(); - return; - } - selectedCatonSize = newValue; - _widthCtl.text = selectedCatonSize!.width.toString(); - _heightCtl.text = selectedCatonSize!.height.toString(); - _lengthCtl.text = selectedCatonSize!.length.toString(); - }); - }, - isExpanded: true, - items: _cartonSizes - .map>((CartonSize value) { - return DropdownMenuItem( - value: value, - child: Text(value.name ?? "", - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: value.name == MANAGE_CARTONSIZE - ? secondaryColor - : primaryColor)), - ); - }).toList(), - ), - ], - ), - ), - ], - ), - ); - } - - _manageCartonSize() { - Navigator.push( - context, - CupertinoPageRoute(builder: (context) => CartonSizeList()), - ); - } - - _removeCargo(CargoType cargo) { - setState(() { - _cargoTypes.remove(cargo); - }); - } - - _updateCargo(CargoType cargo) { - setState(() { - var _c = _cargoTypes.firstWhere((e) => e.id == cargo.id); - _c.weight = cargo.weight; - _c.qty = cargo.qty; - }); - } - - _creatCarton() async { - if (_cargoTypes.length == 0) { - showMsgDialog(context, "Error", "Expect at least one cargo type"); - return; - } - double l = double.parse(_lengthCtl.text); - double w = double.parse(_widthCtl.text); - double h = double.parse(_heightCtl.text); - if ((l <= 0 || w <= 0 || h <= 0)) { - showMsgDialog(context, "Error", "Invalid dimension"); - return; - } - if (_deliveryAddress == null) { - showMsgDialog(context, "Error", "Invalid delivery address"); - return; - } - - Carton carton = Carton(); - carton.id = _carton!.id; - carton.cartonType = _carton!.cartonType; - carton.fcsShipmentID = _carton!.fcsShipmentID; - carton.cargoTypes = _cargoTypes; - if (isFromPackages) { - carton.userID = _carton!.userID; - carton.packages = _carton!.packages.where((e) => e.isChecked).toList(); - } - - if (isFromCartons) { - carton.userID = _carton!.userID; - carton.fcsID = _carton!.fcsID; - carton.userName = _carton!.userName; - carton.senderID = _carton!.senderID; - carton.senderFCSID = _carton!.senderFCSID; - carton.senderName = _carton!.senderName; - } - - carton.length = l; - carton.width = w; - carton.height = h; - carton.deliveryAddress = _deliveryAddress; - setState(() { - _isLoading = true; - }); - try { - CartonModel cartonModel = - Provider.of(context, listen: false); - if (widget.isNew!) { - Carton _c = await cartonModel.createCarton(carton); - Navigator.pop(context, _c); - } else { - await cartonModel.updateCarton(carton); - Carton? _c = await cartonModel.getCarton(_carton!.id!); - if (_c != null) { - Navigator.pop(context, _c); - } - } - } catch (e) { - showMsgDialog(context, "Error", e.toString()); - } finally { - setState(() { - _isLoading = false; - }); - } - } -} diff --git a/lib/pages/carton/carton_list_row.dart b/lib/pages/carton/widget/carton_list_row.dart similarity index 99% rename from lib/pages/carton/carton_list_row.dart rename to lib/pages/carton/widget/carton_list_row.dart index be93d29..c69dfca 100644 --- a/lib/pages/carton/carton_list_row.dart +++ b/lib/pages/carton/widget/carton_list_row.dart @@ -4,7 +4,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; -import 'carton_info.dart'; +import '../carton_info.dart'; class CartonListRow extends StatelessWidget { final Carton box; diff --git a/lib/pages/carton/carton_row.dart b/lib/pages/carton/widget/carton_row.dart similarity index 100% rename from lib/pages/carton/carton_row.dart rename to lib/pages/carton/widget/carton_row.dart diff --git a/lib/pages/carton/user_search_result.dart b/lib/pages/carton/widget/user_search_result.dart similarity index 97% rename from lib/pages/carton/user_search_result.dart rename to lib/pages/carton/widget/user_search_result.dart index 1155b6e..330a089 100644 --- a/lib/pages/carton/user_search_result.dart +++ b/lib/pages/carton/widget/user_search_result.dart @@ -1,8 +1,8 @@ import 'package:fcs/pages/widgets/local_text.dart'; import 'package:flutter/material.dart'; -import '../../../helpers/theme.dart'; -import '../../domain/entities/user.dart'; +import '../../../../helpers/theme.dart'; +import '../../../domain/entities/user.dart'; typedef OnAction = Future Function(); diff --git a/lib/pages/carton/cargo_type_editor.dart b/lib/pages/shipment/cargo_type_editor.dart similarity index 100% rename from lib/pages/carton/cargo_type_editor.dart rename to lib/pages/shipment/cargo_type_editor.dart diff --git a/lib/pages/shipment/shipment_box_editor.dart b/lib/pages/shipment/shipment_box_editor.dart index b89c46c..76e27a7 100644 --- a/lib/pages/shipment/shipment_box_editor.dart +++ b/lib/pages/shipment/shipment_box_editor.dart @@ -2,7 +2,7 @@ import 'package:fcs/domain/entities/carton.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/carton/cargo_type_editor.dart'; +import 'package:fcs/pages/shipment/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';