update shipment type

This commit is contained in:
tzw
2024-03-01 17:27:56 +06:30
parent 1acb2057d4
commit 41a1be745e
14 changed files with 112 additions and 52 deletions

View File

@@ -3,7 +3,6 @@ import 'package:fcs/helpers/theme.dart';
import 'package:fcs/localization/app_translations.dart';
import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart';
import 'package:fcs/pages/main/model/language_model.dart';
import 'package:fcs/pages/main/model/main_model.dart';
import 'package:fcs/pages/widgets/input_date.dart';
import 'package:fcs/pages/widgets/input_text.dart';
import 'package:fcs/pages/widgets/local_app_bar.dart';
@@ -15,6 +14,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import '../../domain/entities/shipment_type.dart';
import '../main/util.dart';
class FcsShipmentEditor extends StatefulWidget {
@@ -39,13 +39,14 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
FcsShipment _shipment = new FcsShipment();
bool _isLoading = false;
String? _currentShipmentType;
ShipmentType? _currentShipmentType;
bool _isNew = false;
@override
void initState() {
super.initState();
_isNew = widget.shipment == null;
var model = Provider.of<FcsShipmentModel>(context, listen: false);
if (widget.shipment != null) {
_shipment = widget.shipment!;
_shipmentNumberController.text = _shipment.shipmentNumber ?? "";
@@ -59,13 +60,13 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
_departureDateControler.text =
dateFormatter.format(_shipment.departureDate!);
_statusController.text = _shipment.status ?? "";
_currentShipmentType = _shipment.shipType;
_consigneeController.text = _shipment.consignee ?? "";
_portController.text = _shipment.port ?? "";
_destinationController.text = _shipment.destination ?? "";
// _currentShipmentType = model.shipmentTypes.where((e) => e.id == _shipment.shipmentTypeId).first;
} else {
var mainModel = Provider.of<MainModel>(context, listen: false);
_currentShipmentType = mainModel.setting!.shipmentTypes[0];
_currentShipmentType = model.shipmentTypes[0];
}
}
@@ -77,7 +78,8 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
@override
Widget build(BuildContext context) {
var languageModel = Provider.of<LanguageModel>(context);
var mainModel = Provider.of<MainModel>(context);
List<ShipmentType> shipmentTypes =
context.watch<FcsShipmentModel>().shipmentTypes;
final createBtn = Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
@@ -171,10 +173,11 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
labelText: AppTranslations.of(context)!
.text('FCSshipment.shipment_type'),
icon: Icon(Ionicons.ios_airplane, color: primaryColor)),
items: mainModel.setting!.shipmentTypes
.map((e) => DropdownMenuItem(child: Text(e), value: e))
items: shipmentTypes
.map((e) =>
DropdownMenuItem(child: Text(e.desc), value: e))
.toList(),
onChanged: (String? selected) => {
onChanged: (selected) => {
setState(() {
_currentShipmentType = selected;
})
@@ -206,7 +209,7 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
FcsShipment fcsShipment = FcsShipment();
fcsShipment.id = _shipment.id;
fcsShipment.shipmentNumber = _shipmentNumberController.text;
fcsShipment.shipType = _currentShipmentType!;
fcsShipment.shipmentTypeId = _currentShipmentType?.id;
fcsShipment.consignee = _consigneeController.text;
fcsShipment.port = _portController.text;
fcsShipment.destination = _destinationController.text;
@@ -262,14 +265,14 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
isDataChanged() {
if (_isNew) {
var mainModel = Provider.of<MainModel>(context, listen: false);
var shipmentModel = Provider.of<FcsShipmentModel>(context, listen: false);
return _shipmentNumberController.text != "" ||
_cutoffDateController.text != "" ||
_arrivalDateController.text != "" ||
_consigneeController.text != "" ||
_portController.text != "" ||
_destinationController.text != "" ||
_currentShipmentType != mainModel.setting!.shipmentTypes[0];
_currentShipmentType != shipmentModel.shipmentTypes[0];
} else {
FcsShipment fcsShipment = _getPayload();
return widget.shipment!.isChangedForEdit(fcsShipment);