This commit is contained in:
phyothandar
2021-09-13 10:15:47 +06:30
9 changed files with 49 additions and 45 deletions

View File

@@ -52,7 +52,7 @@ class Shipment {
this.pickupDate,
this.isCourier = false,
this.radioIndex = 1,
required this.pickupAddress,
this.pickupAddress,
this.pickupUserID,
this.pickupUserName,
this.pickupUserPhoneNumber,

View File

@@ -10,7 +10,6 @@ import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/carton/carton_package_table.dart';
import 'package:fcs/pages/carton_search/carton_search.dart';
import 'package:fcs/pages/carton_size/carton_size_list.dart';
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/package/model/package_model.dart';
@@ -40,8 +39,8 @@ import 'package_carton_editor.dart';
import 'widgets.dart';
class CartonEditor extends StatefulWidget {
final Carton? box;
CartonEditor({this.box});
final Carton? carton;
CartonEditor({this.carton});
@override
_CartonEditorState createState() => _CartonEditorState();
@@ -63,7 +62,7 @@ class _CartonEditorState extends State<CartonEditor> {
double volumetricRatio = 0;
double shipmentWeight = 0;
FcsShipment? _fcsShipment;
List<FcsShipment>? _fcsShipments;
List<FcsShipment> _fcsShipments = [];
List<Carton> _cartons = [];
CartonSize? selectedCatonSize;
@@ -90,8 +89,8 @@ class _CartonEditorState extends State<CartonEditor> {
_widthController.addListener(_calShipmentWeight);
_heightController.addListener(_calShipmentWeight);
if (widget.box != null) {
_carton = widget.box;
if (widget.carton != null) {
_carton = widget.carton;
_deliveryAddress = _carton!.deliveryAddress;
_widthController.text = _carton!.width.toString();
_heightController.text = _carton!.height.toString();
@@ -138,11 +137,13 @@ class _CartonEditorState extends State<CartonEditor> {
FcsShipmentModel fcsShipmentModel =
Provider.of<FcsShipmentModel>(context, listen: false);
var fcsShipments = await fcsShipmentModel.getActiveFcsShipments();
var fcsShipment =
fcsShipments.firstWhere((e) => e.id == _carton!.fcsShipmentID);
// var fcsShipment =
// fcsShipments.firstWhere((e) => e.id == _carton?.fcsShipmentID);
setState(() {
_fcsShipments = fcsShipments;
_fcsShipment = fcsShipment;
// _fcsShipment = fcsShipment;
});
}
@@ -195,9 +196,9 @@ class _CartonEditorState extends State<CartonEditor> {
// }
_calShipmentWeight() {
double l = double.parse(_lengthController.text);
double w = double.parse(_widthController.text);
double h = double.parse(_heightController.text);
double l = double.tryParse(_lengthController.text) ?? 0;
double w = double.tryParse(_widthController.text) ?? 0;
double h = double.tryParse(_heightController.text) ?? 0;
setState(() {
shipmentWeight = l * w * h / volumetricRatio;
});
@@ -248,8 +249,8 @@ class _CartonEditorState extends State<CartonEditor> {
labelKey: "shipment.pack.fcs.shipment",
iconData: Ionicons.ios_airplane,
display: (u) => u.shipmentNumber,
selectedValue: _fcsShipment!,
values: _fcsShipments!,
selectedValue: _fcsShipment,
values: _fcsShipments,
));
final fcsIDBox = Container(

View File

@@ -144,9 +144,9 @@ class _CartonInfoState extends State<CartonInfo> {
}
_calShipmentWeight() {
double l = double.parse(_lengthController.text);
double w = double.parse(_widthController.text);
double h = double.parse(_heightController.text);
double l = double.tryParse(_lengthController.text) ?? 0;
double w = double.tryParse(_widthController.text) ?? 0;
double h = double.tryParse(_heightController.text) ?? 0;
setState(() {
shipmentWeight = l * w * h / volumetricRatio;
});
@@ -412,7 +412,7 @@ class _CartonInfoState extends State<CartonInfo> {
_box!.mixCartons = _box!.mixCartons;
bool? updated = await Navigator.push<bool>(
context,
CupertinoPageRoute(builder: (context) => CartonEditor(box: _box)),
CupertinoPageRoute(builder: (context) => CartonEditor(carton: _box)),
);
if (updated ?? false) {
var cartonModel = Provider.of<CartonModel>(context, listen: false);

View File

@@ -12,8 +12,8 @@ class CustomerModel extends BaseModel {
List<User> customers = [];
List<User> invitations = [];
late StreamSubscription<QuerySnapshot>? customerListener;
late StreamSubscription<QuerySnapshot>? invitationListener;
StreamSubscription<QuerySnapshot>? customerListener;
StreamSubscription<QuerySnapshot>? invitationListener;
@override
void privilegeChanged() {

View File

@@ -96,8 +96,7 @@ class DeliveryAddressModel extends BaseModel {
.orderBy("full_name")
.get();
return querySnap.docs
.map((e) =>
DeliveryAddress.fromMap(e.data as Map<String, dynamic>, e.id))
.map((e) => DeliveryAddress.fromMap(e.data(), e.id))
.toList();
}
}

View File

@@ -108,8 +108,8 @@ class FcsShipmentModel extends BaseModel {
.where("status", isEqualTo: fcs_shipment_confirmed_status)
.get(const GetOptions(source: Source.server));
fcsShipments = snaps.docs.map((documentSnapshot) {
var fcs = FcsShipment.fromMap(
documentSnapshot.data as Map<String, dynamic>, documentSnapshot.id);
var fcs =
FcsShipment.fromMap(documentSnapshot.data(), documentSnapshot.id);
return fcs;
}).toList();
} catch (e) {

View File

@@ -70,10 +70,11 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
_fromTimeEditingController.text = "${timeFormatter.format(now)}";
_toTimeEditingController.text = "${timeFormatter.format(now)}";
// _shipment = Shipment(boxes: []);
var shipmentModel =
Provider.of<DeliveryAddressModel>(context, listen: false);
_shipment!.pickupAddress = shipmentModel.defalutAddress;
_shipment!.boxes = [];
Shipment _s = Shipment(
pickupAddress: context.read<DeliveryAddressModel>().defalutAddress,
boxes: []);
_shipment = _s;
_pickupDate.text = dateFormatter.format(now);
}
}
@@ -87,12 +88,12 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
Widget build(BuildContext context) {
MainModel mainModel = Provider.of<MainModel>(context);
ShipmentModel pickupModel = Provider.of<ShipmentModel>(context);
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment!);
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment);
bool isLocalPickup = _selectedShipmentType == shipment_local_pickup;
bool isCourierPickup = _selectedShipmentType == shipment_courier_pickup;
bool isLocalDropoff = _selectedShipmentType == shipment_local_dropoff;
bool isCourierDropoff = _selectedShipmentType == shipment_courier_dropoff;
var deliveryAddressModel = Provider.of<DeliveryAddressModel>(context);
final fromTimeBox = InputTime(
labelTextKey: 'shipment.from',
iconData: Icons.timer,
@@ -122,7 +123,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
backgroundColor: Colors.white,
));
final pickupAddressBox = DefaultDeliveryAddress(
deliveryAddress: _shipment!.pickupAddress,
deliveryAddress: _shipment?.pickupAddress,
iconData: Icons.location_on,
labelKey: "shipment.location",
onTap: () async {
@@ -130,12 +131,15 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
context,
CupertinoPageRoute(
builder: (context) => DeliveryAddressSelection(
deliveryAddress: _shipment!.pickupAddress,
deliveryAddress: _shipment?.pickupAddress,
user: mainModel.user)),
);
if (address == null) return;
setState(() {
_shipment!.pickupAddress = address;
Shipment _s = Shipment(pickupAddress: address);
_shipment = _s;
});
},
);
@@ -230,17 +234,18 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
color: primaryColor,
),
onPressed: () async {
Carton box = await Navigator.push(
Carton? box = await Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => ShipmentBoxEditor()),
);
if (box == null) return;
_addBox(box);
},
),
),
Column(
children: getBoxList(context, _shipment!.boxes),
children: getBoxList(context, _shipment?.boxes ?? []),
),
_isNew ? createBtn : updateBtn,
],
@@ -324,6 +329,6 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
}
isDataChanged() {
return _shipment!.boxes.isNotEmpty;
return _shipment?.boxes.isNotEmpty;
}
}

View File

@@ -3,21 +3,21 @@ import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:flutter/material.dart';
Widget getShipmentNumberStatus(BuildContext context, Shipment shipment) {
Widget getShipmentNumberStatus(BuildContext context, Shipment? shipment) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
LocalText(
context,
'',
text: shipment.shipmentNumber ?? "",
text: shipment?.shipmentNumber ?? "",
color: primaryColor,
fontSize: 18,
fontWeight: FontWeight.bold,
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Chip(label: Text(shipment.status ?? "")),
child: Chip(label: Text(shipment?.status ?? "")),
),
],
);

View File

@@ -64,8 +64,7 @@ class _DeliveryAddressSelectionState extends State<DeliveryAddressSelection> {
bool? updated = await Navigator.of(context).push(CupertinoPageRoute(
builder: (context) =>
DeliveryAddressEditor(user: widget.user)));
if (updated == null) return;
if (updated) {
if (updated ?? false) {
_getDeliverAddresses();
}
},
@@ -115,10 +114,10 @@ class _DeliveryAddressSelectionState extends State<DeliveryAddressSelection> {
}
_edit(BuildContext context, DeliveryAddress deliveryAddress) async {
bool updated = await Navigator.of(context).push(CupertinoPageRoute(
bool? updated = await Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => DeliveryAddressEditor(
user: widget.user, deliveryAddress: deliveryAddress)));
if (updated) {
if (updated ?? false) {
_getDeliverAddresses();
}
}