diff --git a/assets/local/localization_en.json b/assets/local/localization_en.json index dab65df..b0e84c9 100644 --- a/assets/local/localization_en.json +++ b/assets/local/localization_en.json @@ -293,6 +293,9 @@ "box.carton_size_remove.confirm":"Remove this carton size?", "box.carton_size.name":"Name", "box.cargo_total_title":"Edit Total Weight", + "box.new_carton_btn":"Create new carton", + "box.select.cargo.title":"Select cargos", + "box.complete.packaging":"Complete Packaging", "Boxes End ================================================================":"", "Delivery Start ================================================================":"", @@ -417,6 +420,7 @@ "cargo.type":"Cargo type", "cargo.weight":"Weight", "cargo.rate":"Rate", + "cargo.qty":"Quantity", "cargo.amount":"Amount", "cargo.edit.delete.confirm":"Delete this cargo type?", "Cargo End ================================================================":"", diff --git a/assets/local/localization_mu.json b/assets/local/localization_mu.json index 1b26bf1..5882d12 100644 --- a/assets/local/localization_mu.json +++ b/assets/local/localization_mu.json @@ -293,6 +293,9 @@ "box.carton_size_remove.confirm":"Remove this carton size?", "box.carton_size.name":"နာမည်", "box.cargo_total_title":"စုစုပေါင်းအလေးချိန် ပြုပြင်မည်", + "box.new_carton_btn":"သေတ္တာ အသစ်ပြုလုပ်မည်", + "box.select.cargo.title":"Sကုန်ပစ္စည်းများ ရွေးခြင်း", + "box.complete.packaging":"ထုပ်ပိုးခြင်း ပြီးဆုံးမည်", "Boxes End ================================================================":"", "Delivery Start ================================================================":"", @@ -417,6 +420,7 @@ "cargo.type":"ကုန်ပစ္စည်းအမျိုးအစား", "cargo.weight":"အလေးချိန်", "cargo.rate":"စျေးနှုန်း", + "cargo.qty":"အရေအတွက်", "cargo.amount":"ပမာဏ", "cargo.edit.delete.confirm":"ကုန်ပစ္စည်းကို ဖျက်မလား?", "Cargo End ================================================================":"", diff --git a/lib/domain/entities/cargo_type.dart b/lib/domain/entities/cargo_type.dart index 6534d71..f1da842 100644 --- a/lib/domain/entities/cargo_type.dart +++ b/lib/domain/entities/cargo_type.dart @@ -4,6 +4,7 @@ class CargoType { double rate; double weight; bool isChecked; + int qty; double get calAmount => (calRate ?? 0) * (calWeight ?? 0); @@ -20,15 +21,15 @@ class CargoType { calRate: map['cal_rate']?.toDouble() ?? 0, ); } - CargoType({ - this.id, - this.name, - this.rate, - this.weight, - this.calWeight, - this.calRate, - this.isChecked = false, - }); + CargoType( + {this.id, + this.name, + this.rate, + this.weight, + this.calWeight, + this.calRate, + this.isChecked = false, + this.qty = 0}); Map toMap() { return { diff --git a/lib/pages/carton/cargo_type_addtion.dart b/lib/pages/carton/cargo_type_addtion.dart index 64dff27..c91e022 100644 --- a/lib/pages/carton/cargo_type_addtion.dart +++ b/lib/pages/carton/cargo_type_addtion.dart @@ -3,11 +3,14 @@ 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_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:provider/provider.dart'; +import 'input_text_border.dart'; + class CargoTypeAddition extends StatefulWidget { @override _CargoTypeAdditionState createState() => _CargoTypeAdditionState(); @@ -23,7 +26,11 @@ class _CargoTypeAdditionState extends State { super.initState(); cargos = Provider.of(context, listen: false).rate.cargoTypes; - cargos.forEach((p) => p.isChecked = false); + cargos.forEach((p) { + p.isChecked = false; + p.weight = 0; + p.qty = null; + }); } @override @@ -31,43 +38,109 @@ class _CargoTypeAdditionState extends State { super.dispose(); } - List showcargoTypeList(BuildContext context) { - return this.cargos.map((c) { - return new ListTile( - contentPadding: EdgeInsets.all(0), - title: InkWell( - onTap: () { - setState(() { - c.isChecked = c.isChecked == null ? true : !c.isChecked; - }); - }, - child: new Row( + @override + Widget build(BuildContext context) { + final cargoTableTitleBox = Container( + padding: EdgeInsets.only(left: 0.0, right: 10.0, top: 20), + child: Row( + children: [ + SizedBox( + width: 50, + ), + Expanded( + child: LocalText( + context, + "cargo.type", + color: Colors.grey, + ), + ), + SizedBox( + width: 50, + ), + LocalText( + context, + "cargo.qty", + color: Colors.grey, + ), + Spacer(), + LocalText( + context, + "cargo.weight", + color: Colors.grey, + ), + ], + ), + ); + + List getCargoRowList() { + return cargos.map((c) { + return Container( + child: Container( + padding: + EdgeInsets.only(left: 0.0, right: 5.0, top: 3.0, bottom: 3.0), + decoration: BoxDecoration( + border: Border( + bottom: BorderSide(color: Colors.grey[350], width: 1), + ), + ), + child: Row( children: [ - new Checkbox( - value: c.isChecked == null ? false : c.isChecked, + Checkbox( + value: c.isChecked, activeColor: primaryColor, - onChanged: (bool value) { + onChanged: (bool check) { setState(() { - c.isChecked = value; + c.isChecked = check; }); }), - new Text( - c.name, - style: TextStyle(fontSize: 15.0, color: primaryColor), + Expanded(child: new Text(c.name, style: textStyle)), + SizedBox( + width: 50, + ), + Container( + height: 30, + width: 40, + child: InputTextBorder( + onAdd: (value) { + setState(() { + if (value == "" || value == null) { + c.isChecked = false; + } else { + c.qty = int.parse(value); + c.isChecked = true; + } + }); + }, + ), + ), + Spacer(), + Container( + height: 30, + width: 60, + child: InputTextBorder( + onAdd: (value) { + setState(() { + if (value == "" || value == null) { + c.isChecked = false; + } else { + c.weight = double.parse(value); + c.isChecked = true; + } + }); + }, + ), ), ], ), - )); - }).toList(); - } + ), + ); + }).toList(); + } - @override - Widget build(BuildContext context) { final saveBtn = fcsButton( context, getLocalString(context, 'box.cargo.save.btn'), callack: () { - this.cargos.forEach((p) => p.weight = 0.00); List _cargos = this.cargos.where((c) => c.isChecked).toList(); Navigator.pop(context, _cargos); @@ -92,12 +165,17 @@ class _CargoTypeAdditionState extends State { color: primaryColor, )), body: Container( - padding: EdgeInsets.all(18), + padding: EdgeInsets.all(8), child: ListView( shrinkWrap: true, children: [ + LocalTitle(textKey: "box.select.cargo.title"), + cargoTableTitleBox, + Divider( + color: Colors.grey[400], + ), Column( - children: showcargoTypeList(context), + children: getCargoRowList(), ), SizedBox(height: 30), saveBtn, @@ -108,9 +186,4 @@ class _CargoTypeAdditionState extends State { ), ); } - - // List cargoTypeList() { - // return this.privileges.where((p) => p.isChecked).map((p) => p.id).toList(); - // } - } diff --git a/lib/pages/carton/carton_cargo_table.dart b/lib/pages/carton/carton_cargo_table.dart index 140d8d3..159f9e2 100644 --- a/lib/pages/carton/carton_cargo_table.dart +++ b/lib/pages/carton/carton_cargo_table.dart @@ -41,10 +41,17 @@ class _CargoTableState extends State { ), ), MyDataColumn( - label: LocalText( - context, - "cargo.weight", - color: Colors.grey, + label: Row( + children: [ + Container( + padding: EdgeInsets.only(left:50), + child: LocalText( + context, + "cargo.weight", + color: Colors.grey, + ), + ), + ], ), ), ], @@ -56,32 +63,26 @@ class _CargoTableState extends State { if (widget.cargoTypes == null) { return []; } + List _list = []; + List _types = []; + double _total = 0; var rows = widget.cargoTypes.map((c) { + _total += c.weight; return MyDataRow( - onSelectChanged: (bool selected) async { - if (this.totalWeight <= 0) { - showMsgDialog(context, "Error", "Please insert total weight"); - return; - } - CargoType cargo = await Navigator.push( - context, - CupertinoPageRoute( - builder: (context) => CargoTypeEditor( - cargo: c, - ))); - if (widget.onAdd != null) widget.onAdd(cargo); - if (cargo == null) return; - - this._cargos.add(cargo); - if (this.remainingWeight <= 0) return; - this.remainingWeight -= cargo.weight; - print("this.remainingWeight>>>${this.remainingWeight}"); - }, + onSelectChanged: (bool selected) async {}, cells: [ - MyDataCell(new Text( - c.name == null ? "" : c.name, - style: textStyle, + MyDataCell(Row( + children: [ + new Text( + c.name == null ? "" : c.name, + style: textStyle, + ), + new Text( + c.qty == null ? "" : " x ${c.qty.toString()}", + style: TextStyle(color: Colors.grey), + ), + ], )), MyDataCell( Row( @@ -107,93 +108,6 @@ class _CargoTableState extends State { ); }).toList(); - var totalRow = MyDataRow( - onSelectChanged: (bool selected) async { - double _t = await Navigator.of(context).push(CupertinoPageRoute( - builder: (context) => TotalWeightEdit(totalWeight: totalWeight))); - if (_t == null) return; - setState(() { - totalWeight = _t; - remainingWeight = _t; - }); - }, - cells: [ - MyDataCell(Align( - alignment: Alignment.centerRight, - child: LocalText( - context, - "shipment.cargo.total", - color: Colors.black87, - fontWeight: FontWeight.bold, - ), - )), - MyDataCell( - Padding( - padding: const EdgeInsets.only(right: 48.0), - child: Align( - alignment: Alignment.centerRight, - child: Text(totalWeight.toStringAsFixed(2), - style: TextStyle(fontWeight: FontWeight.bold))), - ), - ), - ], - ); - rows.add(totalRow); - return rows; - } - - double getRemainBalance(double total) { - double _r = this.totalWeight < total ? 0 : this.totalWeight - total; - return _r; - } - - List _getCargoRows(BuildContext context) { - if (widget.cargoTypes == null) { - return []; - } - double total = 0; - var rows = widget.cargoTypes.map((c) { - total += c.weight; - return MyDataRow( - onSelectChanged: (bool selected) async { - CargoType cargo = await Navigator.push( - context, - CupertinoPageRoute( - builder: (context) => CargoTypeEditor( - cargo: c, - ))); - if (widget.onAdd != null) widget.onAdd(cargo); - }, - cells: [ - MyDataCell(new Text( - c.name == null ? "" : c.name, - style: textStyle, - )), - MyDataCell( - Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Text(c.weight == null ? "0" : c.weight.toStringAsFixed(2), - style: textStyle), - widget.onRemove == null - ? SizedBox( - width: 50, - ) - : IconButton( - icon: Icon( - Icons.remove_circle, - color: primaryColor, - ), - onPressed: () { - if (widget.onRemove != null) widget.onRemove(c); - }) - ], - ), - ), - ], - ); - }).toList(); - var totalRow = MyDataRow( onSelectChanged: (bool selected) {}, cells: [ @@ -208,11 +122,53 @@ class _CargoTableState extends State { )), MyDataCell( Padding( - padding: const EdgeInsets.only(right: 48.0), + padding: const EdgeInsets.only(right: 40.0), child: Align( alignment: Alignment.centerRight, - child: Text(total.toStringAsFixed(2), - style: TextStyle(fontWeight: FontWeight.bold))), + child: InkWell( + onTap: () async { + double _t = await Navigator.of(context).push( + CupertinoPageRoute( + builder: (context) => + TotalWeightEdit(totalWeight: totalWeight))); + if (_t == null) return; + setState(() { + totalWeight = _t; + this.remainingWeight = this.totalWeight - _total; + widget.cargoTypes.forEach((c) { + if (c.qty == null) { + this._cargos.add(c); + } + }); + this._cargos.forEach((c) { + _list.add(c.name); + }); + widget.cargoTypes.forEach((c) { + _types.add(c.name); + }); + if (this._cargos.length == widget.cargoTypes.length - 1) { + _types.forEach((t) { + if (!_list.contains(t)) { + widget.cargoTypes.forEach((c) { + if (c.name == t) { + c.weight = this.remainingWeight; + } + }); + } + }); + } + }); + }, + child: Container( + padding: const EdgeInsets.all(7.0), + decoration: BoxDecoration( + border: Border.all(color: Colors.grey), + borderRadius: BorderRadius.all(Radius.circular(5.0)), + ), + child: Text(totalWeight.toStringAsFixed(2), + style: TextStyle(fontWeight: FontWeight.bold)), + ), + )), ), ), ], @@ -220,4 +176,9 @@ class _CargoTableState extends State { rows.add(totalRow); return rows; } + + double getRemainBalance(double total) { + double _r = this.totalWeight < total ? 0 : this.totalWeight - total; + return _r; + } } diff --git a/lib/pages/carton/carton_cargo_table_old.dart b/lib/pages/carton/carton_cargo_table_old.dart new file mode 100644 index 0000000..97dc6a5 --- /dev/null +++ b/lib/pages/carton/carton_cargo_table_old.dart @@ -0,0 +1,255 @@ +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/local_text.dart'; +import 'package:fcs/pages/widgets/my_data_table.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import 'cargo_type_editor.dart'; +import 'total_weight_edit.dart'; + +typedef OnAdd(CargoType cargoType); +typedef OnRemove(CargoType cargoType); + +class CargoTable extends StatefulWidget { + final List cargoTypes; + final OnAdd onAdd; + final OnRemove onRemove; + + const CargoTable({Key key, this.cargoTypes, this.onAdd, this.onRemove}) + : super(key: key); + + @override + _CargoTableState createState() => _CargoTableState(); +} + +class _CargoTableState extends State { + double totalWeight = 0; + List _cargos = []; + double remainingWeight = 0; + @override + Widget build(BuildContext context) { + return 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), + ); + } + + List getCargoRows(BuildContext context) { + if (widget.cargoTypes == null) { + return []; + } + List _list = []; + List _types = []; + + var rows = widget.cargoTypes.map((c) { + return MyDataRow( + onSelectChanged: (bool selected) async { + if (this.totalWeight <= 0) { + showMsgDialog(context, "Error", "Please insert total weight"); + return; + } + CargoType cargo = await Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => CargoTypeEditor( + cargo: c, + ))); + if (widget.onAdd != null) widget.onAdd(cargo); + if (cargo == null) return; + + this._cargos.add(cargo); + if (this.remainingWeight <= 0) return; + this.remainingWeight -= cargo.weight; + + this._cargos.forEach((c) { + _list.add(c.name); + }); + widget.cargoTypes.forEach((c) { + _types.add(c.name); + }); + + if (this._cargos.length == widget.cargoTypes.length - 1) { + _types.forEach((t) { + if (!_list.contains(t)) { + widget.cargoTypes.forEach((c) { + if (c.name == t) { + c.weight = this.remainingWeight; + } + }); + } + }); + } + }, + cells: [ + MyDataCell(new Text( + c.name == null ? "" : c.name, + style: textStyle, + )), + MyDataCell( + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + 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 = MyDataRow( + onSelectChanged: (bool selected) {}, + cells: [ + MyDataCell(Align( + alignment: Alignment.centerRight, + child: LocalText( + context, + "shipment.cargo.total", + color: Colors.black87, + fontWeight: FontWeight.bold, + ), + )), + MyDataCell( + Padding( + padding: const EdgeInsets.only(right: 40.0), + child: Align( + alignment: Alignment.centerRight, + child: InkWell( + onTap: () async { + double _t = await Navigator.of(context).push( + CupertinoPageRoute( + builder: (context) => + TotalWeightEdit(totalWeight: totalWeight))); + if (_t == null) return; + setState(() { + totalWeight = _t; + remainingWeight = _t; + }); + }, + 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; + } + + double getRemainBalance(double total) { + double _r = this.totalWeight < total ? 0 : this.totalWeight - total; + return _r; + } + + List _getCargoRows(BuildContext context) { + if (widget.cargoTypes == null) { + return []; + } + double total = 0; + var rows = widget.cargoTypes.map((c) { + total += c.weight; + return MyDataRow( + onSelectChanged: (bool selected) async { + CargoType cargo = await Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => CargoTypeEditor( + cargo: c, + ))); + if (widget.onAdd != null) widget.onAdd(cargo); + }, + cells: [ + MyDataCell(new Text( + c.name == null ? "" : c.name, + style: textStyle, + )), + MyDataCell( + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Text(c.weight == null ? "0" : c.weight.toStringAsFixed(2), + style: textStyle), + widget.onRemove == null + ? SizedBox( + width: 50, + ) + : IconButton( + icon: Icon( + Icons.remove_circle, + color: primaryColor, + ), + onPressed: () { + if (widget.onRemove != null) widget.onRemove(c); + }) + ], + ), + ), + ], + ); + }).toList(); + + var totalRow = MyDataRow( + onSelectChanged: (bool selected) {}, + cells: [ + MyDataCell(Align( + alignment: Alignment.centerRight, + child: LocalText( + context, + "shipment.cargo.total", + color: Colors.black87, + fontWeight: FontWeight.bold, + ), + )), + MyDataCell( + Padding( + padding: const EdgeInsets.only(right: 48.0), + child: Align( + alignment: Alignment.centerRight, + child: Text(total.toStringAsFixed(2), + style: TextStyle(fontWeight: FontWeight.bold))), + ), + ), + ], + ); + rows.add(totalRow); + return rows; + } +} diff --git a/lib/pages/carton/carton_editor.dart b/lib/pages/carton/carton_editor.dart index 724047a..e1f6aed 100644 --- a/lib/pages/carton/carton_editor.dart +++ b/lib/pages/carton/carton_editor.dart @@ -35,6 +35,7 @@ import 'cargo_type_addtion.dart'; import 'cargo_type_editor.dart'; import 'model/carton_model.dart'; import '../carton_size/model/carton_size_model.dart'; +import 'package_carton_editor.dart'; import 'widgets.dart'; class CartonEditor extends StatefulWidget { @@ -63,6 +64,8 @@ class _CartonEditorState extends State { Carton _mixCarton; List _mixCartons; + List _cartons = []; + @override void initState() { super.initState(); @@ -96,6 +99,11 @@ class _CartonEditorState extends State { _isNew = true; _selectedCartonType = carton_from_packages; _loadFcsShipments(); + _cartons = [ + Carton(cartonNumber: "A100B-1#1"), + Carton(cartonNumber: "A100B-1#2"), + Carton(cartonNumber: "A100B-1#3") + ]; } } @@ -297,7 +305,7 @@ class _CartonEditorState extends State { ); final createBtn = LocalButton( - textKey: "box.create.btn", + textKey: "box.complete.packaging", callBack: _save, ); @@ -344,6 +352,28 @@ class _CartonEditorState extends State { onRemove: (c) => _removeCargo(c), ); + final cartonTitleBox = Container( + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Text("Cartons (${_cartons.length})"), + IconButton( + icon: Icon( + Icons.add_circle, + color: primaryColor, + ), + onPressed: () async { + Carton _carton = await Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => PackageCartonEditor()), + ); + _addCarton(_carton); + }), + ], + ), + ); + return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( @@ -359,19 +389,25 @@ class _CartonEditorState extends State { ), shadowColor: Colors.transparent, backgroundColor: Colors.white, - title: _isNew - ? LocalText( - context, - "boxes.create.title", - fontSize: 20, - color: primaryColor, - ) - : LocalText( - context, - "box.edit.title", - fontSize: 20, - color: primaryColor, - ), + title: LocalText( + context, + "box.info.title", + fontSize: 20, + color: primaryColor, + ), + // title: _isNew + // ? LocalText( + // context, + // "boxes.create.title", + // fontSize: 20, + // color: primaryColor, + // ) + // : LocalText( + // context, + // "box.edit.title", + // fontSize: 20, + // color: primaryColor, + // ), ), body: Padding( padding: const EdgeInsets.all(8.0), @@ -418,32 +454,41 @@ class _CartonEditorState extends State { _populateDeliveryAddress(); }, ), - cargoTableTitleBox, - cargoTableBox, - isSmallBag - ? Container() - : LocalTitle(textKey: "box.dimension"), - isSmallBag ? Container() : cartonSizeDropdown(), - isSmallBag ? Container() : dimBox, - isSmallBag ? Container() : shipmentWeightBox, - LocalTitle(textKey: "box.delivery_address"), - DefaultDeliveryAddress( - deliveryAddress: _deliveryAddress, - labelKey: "box.delivery_address", - onTap: () async { - DeliveryAddress _address = await Navigator.push( - context, - CupertinoPageRoute( - builder: (context) => DeliveryAddressList( - isAdminCreation: true, - deliveryAddress: _deliveryAddress))); - if (_address == null) return; - setState(() { - _deliveryAddress = _address; - }); - }, - ), + cartonTitleBox, + Column( + children: _getCartons( + context, + this._cartons, + )), + // cargoTableTitleBox, + // cargoTableBox, + // isSmallBag + // ? Container() + // : LocalTitle(textKey: "box.dimension"), + // isSmallBag ? Container() : cartonSizeDropdown(), + // isSmallBag ? Container() : dimBox, + // isSmallBag ? Container() : shipmentWeightBox, + // LocalTitle(textKey: "box.delivery_address"), + // DefaultDeliveryAddress( + // deliveryAddress: _deliveryAddress, + // labelKey: "box.delivery_address", + // onTap: () async { + // DeliveryAddress _address = await Navigator.push( + // context, + // CupertinoPageRoute( + // builder: (context) => DeliveryAddressList( + // isAdminCreation: true, + // deliveryAddress: _deliveryAddress))); + // if (_address == null) return; + // setState(() { + // _deliveryAddress = _address; + // }); + // }, + // ), ]), + SizedBox( + height: 20, + ), _isNew ? createBtn : saveBtn, SizedBox( height: 20, @@ -455,6 +500,65 @@ class _CartonEditorState extends State { ); } + _addCarton(Carton carton) { + if (carton == null) return; + this._cartons.add(carton); + setState(() {}); + } + + List _getCartons(BuildContext context, List cartons) { + return cartons.map((c) { + return Container( + decoration: BoxDecoration( + border: Border( + bottom: BorderSide(color: Colors.grey[300]), + ), + ), + child: InkWell( + onTap: () {}, + child: Row( + children: [ + Expanded( + child: new Padding( + padding: const EdgeInsets.symmetric(vertical: 10.0), + child: new Row( + children: [ + new Padding( + padding: + new EdgeInsets.symmetric(horizontal: 15.0 - 5 / 2), + child: Stack( + alignment: AlignmentDirectional.bottomEnd, + children: [ + Icon( + MaterialCommunityIcons.package, + color: primaryColor, + size: 30, + ), + ], + ), + ), + new Expanded( + child: new Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + new Text( + c.cartonNumber == null ? "" : c.cartonNumber, + style: new TextStyle(fontSize: 15.0), + ), + ], + ), + ), + ], + ), + ), + ), + ], + ), + ), + ); + }).toList(); + } + CartonSize selectedCatonSize; Widget cartonSizeDropdown() { List _cartonSizes = diff --git a/lib/pages/carton/input_text_border.dart b/lib/pages/carton/input_text_border.dart new file mode 100644 index 0000000..949c00d --- /dev/null +++ b/lib/pages/carton/input_text_border.dart @@ -0,0 +1,27 @@ +import 'package:flutter/material.dart'; + +typedef OnAdd(String value); + +class InputTextBorder extends StatelessWidget { + final OnAdd onAdd; + + const InputTextBorder({Key key, this.onAdd}) : super(key: key); + @override + Widget build(BuildContext context) { + return TextFormField( + textAlign: TextAlign.center, + onChanged: (v) { + if (onAdd != null) onAdd(v); + }, + keyboardType: TextInputType.number, + decoration: new InputDecoration( + focusedBorder: OutlineInputBorder( + borderSide: BorderSide(color: Colors.grey), + ), + enabledBorder: OutlineInputBorder( + borderSide: BorderSide(color: Colors.grey), + ), + ), + ); + } +} diff --git a/lib/pages/carton/package_carton_editor.dart b/lib/pages/carton/package_carton_editor.dart new file mode 100644 index 0000000..b54e62f --- /dev/null +++ b/lib/pages/carton/package_carton_editor.dart @@ -0,0 +1,310 @@ +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/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/delivery_address/model/delivery_address_model.dart'; +import 'package:fcs/pages/rates/model/shipment_rate_model.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/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_icons/flutter_icons.dart'; +import 'package:provider/provider.dart'; + +import 'cargo_type_addtion.dart'; +import 'carton_cargo_table.dart'; + +class PackageCartonEditor extends StatefulWidget { + final Carton box; + PackageCartonEditor({this.box}); + + @override + _PackageCartonEditorState createState() => _PackageCartonEditorState(); +} + +class _PackageCartonEditorState extends State { + TextEditingController _lengthCtl = new TextEditingController(); + TextEditingController _widthCtl = new TextEditingController(); + TextEditingController _heightCtl = new TextEditingController(); + + Carton _box; + bool _isLoading = false; + bool _isNew; + double volumetricRatio = 0; + double shipmentWeight = 0; + + @override + void initState() { + super.initState(); + + volumetricRatio = Provider.of(context, listen: false) + .rate + .volumetricRatio; + + if (widget.box != null) { + _box = widget.box; + _isNew = false; + _lengthCtl.text = _box.length.toString(); + _widthCtl.text = _box.width.toString(); + _heightCtl.text = _box.height.toString(); + } else { + var shipmentModel = + Provider.of(context, listen: false); + + _isNew = true; + _box = Carton(cargoTypes: []); + _box.deliveryAddress = shipmentModel.defalutAddress; + + _lengthCtl.text = "12"; + _widthCtl.text = "12"; + _heightCtl.text = "12"; + } + _lengthCtl.addListener(_calShipmentWeight); + _widthCtl.addListener(_calShipmentWeight); + _heightCtl.addListener(_calShipmentWeight); + _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).ceilToDouble(); + }); + } + + @override + Widget build(BuildContext context) { + final shipmentWeightBox = DisplayText( + labelTextKey: "box.shipment_weight", + text: shipmentWeight == null ? "" : shipmentWeight.toStringAsFixed(0), + iconData: MaterialCommunityIcons.weight, + ); + + final lengthBox = LengthPicker( + controller: _lengthCtl, + lableKey: "box.length", + isReadOnly: true, + ); + final widthBox = LengthPicker( + controller: _widthCtl, + lableKey: "box.width", + isReadOnly: true, + ); + final heightBox = LengthPicker( + controller: _heightCtl, + lableKey: "box.height", + isReadOnly: true, + ); + 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: "box.new_carton_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(() { + _box.cargoTypes.clear(); + _box.cargoTypes.addAll(cargos); + }); + }), + ); + + final cargoTableBox = CargoTable( + cargoTypes: _box.cargoTypes, + onAdd: (c) => _addCargo(c), + onRemove: (c) => _removeCargo(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, + _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, + shipmentWeightBox, + LocalTitle(textKey: "box.delivery_address"), + DefaultDeliveryAddress( + deliveryAddress: _box.deliveryAddress, + labelKey: "box.delivery_address", + onTap: () async { + DeliveryAddress d = await Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => DeliveryAddressSelection( + deliveryAddress: _box.deliveryAddress, + )), + ); + if (d == null) return; + setState(() { + _box.deliveryAddress = d; + }); + }), + SizedBox( + height: 20, + ), + createBtn + ], + ), + ), + ), + ); + } + + CartonSize selectedCatonSize; + 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()), + ); + } + + _addCargo(CargoType cargo) { + if (cargo == null) return; + setState(() { + _box.cargoTypes.remove(cargo); + _box.cargoTypes.add(cargo); + }); + } + + _removeCargo(CargoType cargo) { + setState(() { + _box.cargoTypes.remove(cargo); + }); + } + + _creatCarton() { + // double l = double.parse(_lengthCtl.text, (s) => 0); + // double w = double.parse(_widthCtl.text, (s) => 0); + // double h = double.parse(_heightCtl.text, (s) => 0); + // _box.length = l; + // _box.width = w; + // _box.height = h; + // Navigator.pop(context, _box); + } +}