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

View File

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

View File

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

View File

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

View File

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

View File

@@ -70,10 +70,11 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
_fromTimeEditingController.text = "${timeFormatter.format(now)}"; _fromTimeEditingController.text = "${timeFormatter.format(now)}";
_toTimeEditingController.text = "${timeFormatter.format(now)}"; _toTimeEditingController.text = "${timeFormatter.format(now)}";
// _shipment = Shipment(boxes: []); // _shipment = Shipment(boxes: []);
var shipmentModel =
Provider.of<DeliveryAddressModel>(context, listen: false); Shipment _s = Shipment(
_shipment!.pickupAddress = shipmentModel.defalutAddress; pickupAddress: context.read<DeliveryAddressModel>().defalutAddress,
_shipment!.boxes = []; boxes: []);
_shipment = _s;
_pickupDate.text = dateFormatter.format(now); _pickupDate.text = dateFormatter.format(now);
} }
} }
@@ -87,12 +88,12 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
MainModel mainModel = Provider.of<MainModel>(context); MainModel mainModel = Provider.of<MainModel>(context);
ShipmentModel pickupModel = Provider.of<ShipmentModel>(context); ShipmentModel pickupModel = Provider.of<ShipmentModel>(context);
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment!); final shipmentNumberBox = getShipmentNumberStatus(context, _shipment);
bool isLocalPickup = _selectedShipmentType == shipment_local_pickup; bool isLocalPickup = _selectedShipmentType == shipment_local_pickup;
bool isCourierPickup = _selectedShipmentType == shipment_courier_pickup; bool isCourierPickup = _selectedShipmentType == shipment_courier_pickup;
bool isLocalDropoff = _selectedShipmentType == shipment_local_dropoff; bool isLocalDropoff = _selectedShipmentType == shipment_local_dropoff;
bool isCourierDropoff = _selectedShipmentType == shipment_courier_dropoff; bool isCourierDropoff = _selectedShipmentType == shipment_courier_dropoff;
var deliveryAddressModel = Provider.of<DeliveryAddressModel>(context);
final fromTimeBox = InputTime( final fromTimeBox = InputTime(
labelTextKey: 'shipment.from', labelTextKey: 'shipment.from',
iconData: Icons.timer, iconData: Icons.timer,
@@ -122,7 +123,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
backgroundColor: Colors.white, backgroundColor: Colors.white,
)); ));
final pickupAddressBox = DefaultDeliveryAddress( final pickupAddressBox = DefaultDeliveryAddress(
deliveryAddress: _shipment!.pickupAddress, deliveryAddress: _shipment?.pickupAddress,
iconData: Icons.location_on, iconData: Icons.location_on,
labelKey: "shipment.location", labelKey: "shipment.location",
onTap: () async { onTap: () async {
@@ -130,12 +131,15 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
context, context,
CupertinoPageRoute( CupertinoPageRoute(
builder: (context) => DeliveryAddressSelection( builder: (context) => DeliveryAddressSelection(
deliveryAddress: _shipment!.pickupAddress, deliveryAddress: _shipment?.pickupAddress,
user: mainModel.user)), user: mainModel.user)),
); );
if (address == null) return; if (address == null) return;
setState(() { setState(() {
_shipment!.pickupAddress = address; Shipment _s = Shipment(pickupAddress: address);
_shipment = _s;
}); });
}, },
); );
@@ -230,17 +234,18 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
color: primaryColor, color: primaryColor,
), ),
onPressed: () async { onPressed: () async {
Carton box = await Navigator.push( Carton? box = await Navigator.push(
context, context,
CupertinoPageRoute( CupertinoPageRoute(
builder: (context) => ShipmentBoxEditor()), builder: (context) => ShipmentBoxEditor()),
); );
if (box == null) return;
_addBox(box); _addBox(box);
}, },
), ),
), ),
Column( Column(
children: getBoxList(context, _shipment!.boxes), children: getBoxList(context, _shipment?.boxes ?? []),
), ),
_isNew ? createBtn : updateBtn, _isNew ? createBtn : updateBtn,
], ],
@@ -324,6 +329,6 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
} }
isDataChanged() { 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:fcs/pages/widgets/local_text.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
Widget getShipmentNumberStatus(BuildContext context, Shipment shipment) { Widget getShipmentNumberStatus(BuildContext context, Shipment? shipment) {
return Row( return Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
LocalText( LocalText(
context, context,
'', '',
text: shipment.shipmentNumber ?? "", text: shipment?.shipmentNumber ?? "",
color: primaryColor, color: primaryColor,
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
Padding( Padding(
padding: const EdgeInsets.only(left: 8.0), 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( bool? updated = await Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => builder: (context) =>
DeliveryAddressEditor(user: widget.user))); DeliveryAddressEditor(user: widget.user)));
if (updated == null) return; if (updated ?? false) {
if (updated) {
_getDeliverAddresses(); _getDeliverAddresses();
} }
}, },
@@ -115,10 +114,10 @@ class _DeliveryAddressSelectionState extends State<DeliveryAddressSelection> {
} }
_edit(BuildContext context, DeliveryAddress deliveryAddress) async { _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( builder: (context) => DeliveryAddressEditor(
user: widget.user, deliveryAddress: deliveryAddress))); user: widget.user, deliveryAddress: deliveryAddress)));
if (updated) { if (updated ?? false) {
_getDeliverAddresses(); _getDeliverAddresses();
} }
} }