From a246097d05acb0d7e146bc0d46a8d5ab19494260 Mon Sep 17 00:00:00 2001 From: tzw Date: Fri, 9 Feb 2024 17:10:19 +0630 Subject: [PATCH] add carton editor to update --- assets/local/localization_en.json | 3 +- assets/local/localization_mu.json | 2 + lib/pages/carton/carton_package_editor.dart | 39 +++++++++++----- lib/pages/carton/carton_size_widget.dart | 44 +++++++++++-------- lib/pages/carton/carton_submit.dart | 7 ++- .../carton/mix_carton/mix_carton_editor.dart | 26 +++++++++-- .../carton/mix_carton/mix_carton_submit.dart | 7 ++- lib/pages/carton/mix_carton/type_widget.dart | 17 ++++--- .../model/fcs_shipment_model.dart | 3 +- 9 files changed, 103 insertions(+), 45 deletions(-) diff --git a/assets/local/localization_en.json b/assets/local/localization_en.json index af74e52..08838f9 100644 --- a/assets/local/localization_en.json +++ b/assets/local/localization_en.json @@ -345,7 +345,8 @@ "box.delvery_carton":"Delivery carton", "box.pick_up_carton":"Pick-up carton", "box.delete.btn":"Delete carton", - + "box.update_title":"Edit carton", + "box.update.btn":"Update carton", "Boxes End ================================================================":"", "Delivery Start ================================================================":"", diff --git a/assets/local/localization_mu.json b/assets/local/localization_mu.json index d5cb055..9feba78 100644 --- a/assets/local/localization_mu.json +++ b/assets/local/localization_mu.json @@ -344,6 +344,8 @@ "box.delvery_carton":"Delivery carton", "box.pick_up_carton":"Pick-up carton", "box.delete.btn":"Delete carton", + "box.update_title":"Edit carton", + "box.update.btn":"Update carton", "Boxes End ================================================================":"", "Delivery Start ================================================================":"", diff --git a/lib/pages/carton/carton_package_editor.dart b/lib/pages/carton/carton_package_editor.dart index e0bf4e3..a13be1a 100644 --- a/lib/pages/carton/carton_package_editor.dart +++ b/lib/pages/carton/carton_package_editor.dart @@ -14,6 +14,7 @@ import '../../domain/entities/cargo_type.dart'; import '../../domain/entities/carton.dart'; import '../../domain/entities/package.dart'; import '../../domain/entities/user.dart'; +import '../fcs_shipment/model/fcs_shipment_model.dart'; import '../main/util.dart'; import '../widgets/local_text.dart'; import '../widgets/progress.dart'; @@ -64,20 +65,37 @@ class _CartonPackageEditorState extends State { @override void initState() { + _init(); + super.initState(); + } + + _init() async { _sender = User( - name: "ptd-phyo44 kaelone", - fcsID: "FCS-8X6V", - phoneNumber: "+959444444444", - id: "48u_4s-HiQeW-HwSqeRd9TSMWh3mLZfSk5rpaUEh_zw"); + name: widget.carton.senderName, + fcsID: widget.carton.senderFCSID, + id: widget.carton.senderID); _consignee = User( - id: "HsIwG88K-0_HSazgEy5QR27kcjkOvfv7_Sr1JP18Q1A", - name: "One One", - phoneNumber: "+959111111111", - fcsID: "FCS-EFRF"); + id: widget.carton.userID, + name: widget.carton.userName, + fcsID: widget.carton.fcsID); + + _billToValue = widget.carton.billTo ?? billToSender; + _selectedDeliveryType = delivery_caton; + _cartonSizeType = customCarton; + _length = widget.carton.length; + _width = widget.carton.width; + _height = widget.carton.height; + + var s = await context + .read() + .getFcsShipment(widget.carton.fcsShipmentID ?? ""); + _shipment = s; context.read().clearSelection(); - super.initState(); + if (mounted) { + setState(() {}); + } } @override @@ -116,7 +134,7 @@ class _CartonPackageEditorState extends State { }, ), backgroundColor: Colors.white, - title: LocalText(context, 'boxes.new', + title: LocalText(context, 'box.update_title', color: primaryColor, fontSize: 20), ), body: Column( @@ -220,6 +238,7 @@ class _CartonPackageEditorState extends State { } else { return Expanded( child: CartonSubmit( + isNew: false, sender: _sender!, consingee: _consignee!, billToValue: _billToValue, diff --git a/lib/pages/carton/carton_size_widget.dart b/lib/pages/carton/carton_size_widget.dart index 8aa89ef..54982f1 100644 --- a/lib/pages/carton/carton_size_widget.dart +++ b/lib/pages/carton/carton_size_widget.dart @@ -63,7 +63,7 @@ class _CartonSizeWidgetState extends State { List _deliveryTypes = [delivery_caton, pickup_carton]; FcsShipment? _shipment; - String _cartionSizeType = standardCarton; + String _cartonSizeType = standardCarton; List _shipments = []; CartonSize? _selectStandardSize; @@ -83,34 +83,40 @@ class _CartonSizeWidgetState extends State { _init() async { _selectedDeliveryType = widget.deliveryType; _billToValue = widget.billType; - _shipment = widget.shipment; - _cartionSizeType = widget.cartonSizeType; + _cartonSizeType = widget.cartonSizeType; List cartonSizes = context.read().cartonSizes; _selectStandardSize = widget.standardSize ?? cartonSizes.first; _lengthController.text = - widget.length == null ? "0" : widget.length.toString(); + widget.length == null ? "0" : removeTrailingZeros(widget.length ?? 0); _widthController.text = - widget.width == null ? "0" : widget.width.toString(); + widget.width == null ? "0" : removeTrailingZeros(widget.width ?? 0); _heightController.text = - widget.height == null ? "0" : widget.height.toString(); + widget.height == null ? "0" : removeTrailingZeros(widget.height ?? 0); var fcsShipments = await context.read().getActiveFcsShipments(); _shipments = fcsShipments; + _shipment = widget.shipment; if (mounted) { setState(() {}); } } + @override + void didUpdateWidget(covariant CartonSizeWidget oldWidget) { + _init(); + super.didUpdateWidget(oldWidget); + } + @override Widget build(BuildContext context) { List cartonSizes = context.watch().cartonSizes; - bool isStandardSize = _cartionSizeType == standardCarton; - bool isCustomSize = _cartionSizeType == customCarton; - bool isNoneDefinedSize = _cartionSizeType == packageCartion; + bool isStandardSize = _cartonSizeType == standardCarton; + bool isCustomSize = _cartonSizeType == customCarton; + bool isNoneDefinedSize = _cartonSizeType == packageCartion; final senderBox = DisplayText( text: widget.sender.name, @@ -242,7 +248,7 @@ class _CartonSizeWidgetState extends State { if (widget.onContinue != null) { widget.onContinue!( - _selectedDeliveryType, _billToValue, _shipment!, _cartionSizeType, + _selectedDeliveryType, _billToValue, _shipment!, _cartonSizeType, standardSize: _selectStandardSize, length: l, width: w, height: h); } }); @@ -321,16 +327,16 @@ class _CartonSizeWidgetState extends State { InkWell( onTap: () { setState(() { - _cartionSizeType = standardCarton; + _cartonSizeType = standardCarton; }); }, child: Row(children: [ LocalRadio( value: standardCarton, - groupValue: _cartionSizeType, + groupValue: _cartonSizeType, onChanged: (p0) { setState(() { - _cartionSizeType = standardCarton; + _cartonSizeType = standardCarton; }); }, ), @@ -350,16 +356,16 @@ class _CartonSizeWidgetState extends State { InkWell( onTap: () { setState(() { - _cartionSizeType = customCarton; + _cartonSizeType = customCarton; }); }, child: Row(children: [ LocalRadio( value: customCarton, - groupValue: _cartionSizeType, + groupValue: _cartonSizeType, onChanged: (p0) { setState(() { - _cartionSizeType = customCarton; + _cartonSizeType = customCarton; }); }, ), @@ -379,16 +385,16 @@ class _CartonSizeWidgetState extends State { InkWell( onTap: () { setState(() { - _cartionSizeType = packageCartion; + _cartonSizeType = packageCartion; }); }, child: Row(children: [ LocalRadio( value: packageCartion, - groupValue: _cartionSizeType, + groupValue: _cartonSizeType, onChanged: (p0) { setState(() { - _cartionSizeType = packageCartion; + _cartonSizeType = packageCartion; }); }, ), diff --git a/lib/pages/carton/carton_submit.dart b/lib/pages/carton/carton_submit.dart index cbad83f..681896d 100644 --- a/lib/pages/carton/carton_submit.dart +++ b/lib/pages/carton/carton_submit.dart @@ -35,6 +35,7 @@ class CartonSubmit extends StatelessWidget { final List surchareItems; final OnCreateCarton? onCreate; final OnPrevious? onPrevious; + final bool isNew; const CartonSubmit( {Key? key, required this.sender, @@ -51,7 +52,8 @@ class CartonSubmit extends StatelessWidget { this.width = 0, this.height = 0, this.cargoTypes = const [], - this.surchareItems = const []}) + this.surchareItems = const [], + this.isNew = true}) : super(key: key); @override @@ -310,7 +312,8 @@ class CartonSubmit extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ Flexible( - child: LocalText(context, 'box.crete.carton', + child: LocalText( + context, isNew ? 'box.crete.carton' : "box.update.btn", color: Colors.white, fontSize: 15), ), const SizedBox(width: 5), diff --git a/lib/pages/carton/mix_carton/mix_carton_editor.dart b/lib/pages/carton/mix_carton/mix_carton_editor.dart index ed31519..da251d3 100644 --- a/lib/pages/carton/mix_carton/mix_carton_editor.dart +++ b/lib/pages/carton/mix_carton/mix_carton_editor.dart @@ -1,5 +1,6 @@ // ignore_for_file: deprecated_member_use +import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; @@ -50,10 +51,26 @@ class _MixCartonEditorState extends State { @override void initState() { - context.read().clearSelection(); + _init(); super.initState(); } + _init() async { + var s = await context + .read() + .getFcsShipment(widget.carton.fcsShipmentID ?? ""); + _shipment = s; + _cartonSizeType = customCarton; + _length = widget.carton.length; + _width = widget.carton.width; + _height = widget.carton.height; + + context.read().clearSelection(); + if (mounted) { + setState(() {}); + } + } + @override Widget build(BuildContext context) { return WillPopScope( @@ -90,7 +107,7 @@ class _MixCartonEditorState extends State { }, ), backgroundColor: Colors.white, - title: LocalText(context, 'boxes.new', + title: LocalText(context, 'box.update_title', color: primaryColor, fontSize: 20), ), body: Column( @@ -163,6 +180,7 @@ class _MixCartonEditorState extends State { } else { return Expanded( child: MixCartonSubmit( + isNew: false, cartonSizeType: _cartonSizeType, standardSize: _standardSize, length: _length, @@ -171,7 +189,7 @@ class _MixCartonEditorState extends State { shipment: _shipment!, cartons: _cartons, onCreate: () { - _create(); + _update(); }, onPrevious: () { setState(() { @@ -183,7 +201,7 @@ class _MixCartonEditorState extends State { } } - _create() async { + _update() async { setState(() { _isLoading = true; }); diff --git a/lib/pages/carton/mix_carton/mix_carton_submit.dart b/lib/pages/carton/mix_carton/mix_carton_submit.dart index 894471b..456ca16 100644 --- a/lib/pages/carton/mix_carton/mix_carton_submit.dart +++ b/lib/pages/carton/mix_carton/mix_carton_submit.dart @@ -18,6 +18,7 @@ typedef OnCreateMixCarton = Function(); typedef OnPrevious = Function(); class MixCartonSubmit extends StatefulWidget { + final bool isNew; final FcsShipment shipment; final List cartons; final String cartonSizeType; @@ -37,7 +38,8 @@ class MixCartonSubmit extends StatefulWidget { required this.cartonSizeType, this.length = 0, this.width = 0, - this.height = 0}) + this.height = 0, + this.isNew = true}) : super(key: key); @override @@ -253,7 +255,8 @@ class _MixCartonSubmitState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ Flexible( - child: LocalText(context, 'box.crete.carton', + child: LocalText(context, + widget.isNew ? 'box.crete.carton' : 'box.update.btn', color: Colors.white, fontSize: 15), ), const SizedBox(width: 5), diff --git a/lib/pages/carton/mix_carton/type_widget.dart b/lib/pages/carton/mix_carton/type_widget.dart index ccc2c32..3eccba4 100644 --- a/lib/pages/carton/mix_carton/type_widget.dart +++ b/lib/pages/carton/mix_carton/type_widget.dart @@ -65,28 +65,33 @@ class _TypeWidgetState extends State { } _init() async { - _shipment = widget.shipment; - _cartionSizeType = widget.cartonSizeType; - List cartonSizes = context.read().cartonSizes; _selectStandardSize = widget.standardSize ?? cartonSizes.first; + _cartionSizeType = widget.cartonSizeType; _lengthController.text = - widget.length == null ? "0" : widget.length.toString(); + widget.length == null ? "0" : removeTrailingZeros(widget.length ?? 0); _widthController.text = - widget.width == null ? "0" : widget.width.toString(); + widget.width == null ? "0" : removeTrailingZeros(widget.width ?? 0); _heightController.text = - widget.height == null ? "0" : widget.height.toString(); + widget.height == null ? "0" : removeTrailingZeros(widget.height ?? 0); var fcsShipments = await context.read().getActiveFcsShipments(); _shipments = fcsShipments; + _shipment = widget.shipment; if (mounted) { setState(() {}); } } + @override + void didUpdateWidget(covariant TypeWidget oldWidget) { + _init(); + super.didUpdateWidget(oldWidget); + } + @override Widget build(BuildContext context) { List cartonSizes = context.watch().cartonSizes; diff --git a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart index 5c5f764..c921bd3 100644 --- a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart +++ b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart @@ -83,7 +83,7 @@ class FcsShipmentModel extends BaseModel { try { var snaps = await FirebaseFirestore.instance .collection("/$fcs_shipment_collection") - .where("status", isEqualTo: fcs_shipment_confirmed_status) + // .where("status", isEqualTo: fcs_shipment_confirmed_status) .get(const GetOptions(source: Source.server)); fcsShipments = snaps.docs.map((documentSnapshot) { var fcs = @@ -97,6 +97,7 @@ class FcsShipmentModel extends BaseModel { } Future getFcsShipment(String id) async { + if (id == "") return null; try { var snap = await FirebaseFirestore.instance .collection("/$fcs_shipment_collection")