null safety
This commit is contained in:
@@ -20,7 +20,7 @@ import 'package:fcs/pages/widgets/multi_img_controller.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:flutter_icons_null_safety/flutter_icons_null_safety.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
@@ -32,8 +32,8 @@ import 'shipment_editor.dart';
|
||||
import 'widgets.dart';
|
||||
|
||||
class ShipmentInfo extends StatefulWidget {
|
||||
final bool isCustomer;
|
||||
final Shipment shipment;
|
||||
final bool? isCustomer;
|
||||
final Shipment? shipment;
|
||||
ShipmentInfo({this.shipment, this.isCustomer});
|
||||
|
||||
@override
|
||||
@@ -62,39 +62,42 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
TextEditingController _pickupDate = new TextEditingController();
|
||||
TextEditingController _handlingFeeController = new TextEditingController();
|
||||
|
||||
Shipment _shipment;
|
||||
Shipment? _shipment;
|
||||
bool _isLoading = false;
|
||||
bool _isCustomer;
|
||||
late bool _isCustomer;
|
||||
var now = new DateTime.now();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_shipment = widget.shipment;
|
||||
_isCustomer = widget.isCustomer;
|
||||
_loadCartons(_shipment.id);
|
||||
_isCustomer = widget.isCustomer!;
|
||||
_loadCartons(_shipment!.id!);
|
||||
|
||||
_addressEditingController.text = _shipment.address;
|
||||
_fromTimeEditingController.text = _shipment.pickupTimeStart;
|
||||
_toTimeEditingController.text = _shipment.pickupTimeEnd;
|
||||
_noOfPackageEditingController.text = _shipment.numberOfPackage.toString();
|
||||
_weightEditingController.text = _shipment.weight.toString();
|
||||
_pickupDate.text = dateFormatter.format(_shipment.pickupDate ?? now);
|
||||
_addressEditingController.text = _shipment!.address ?? "";
|
||||
_fromTimeEditingController.text = _shipment!.pickupTimeStart ?? "";
|
||||
_toTimeEditingController.text = _shipment!.pickupTimeEnd ?? "";
|
||||
_noOfPackageEditingController.text = _shipment!.numberOfPackage != null
|
||||
? _shipment!.numberOfPackage.toString()
|
||||
: "";
|
||||
_weightEditingController.text =
|
||||
_shipment!.weight != null ? _shipment!.weight.toString() : "";
|
||||
_pickupDate.text = dateFormatter.format(_shipment!.pickupDate ?? now);
|
||||
}
|
||||
|
||||
_loadCartons(String shipmentID) async {
|
||||
CartonModel cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
var cartons = await cartonModel.getCartons(shipmentID);
|
||||
setState(() {
|
||||
_shipment.boxes = cartons;
|
||||
_shipment!.boxes = cartons;
|
||||
});
|
||||
}
|
||||
|
||||
_loadShipment(String id) async {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
Shipment s = await shipmentModel.getShipment(id);
|
||||
s.boxes = _shipment.boxes;
|
||||
Shipment? s = await shipmentModel.getShipment(id);
|
||||
s!.boxes = _shipment!.boxes;
|
||||
setState(() {
|
||||
_shipment = s;
|
||||
});
|
||||
@@ -109,31 +112,34 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
Widget build(BuildContext context) {
|
||||
MainModel mainModel = Provider.of<MainModel>(context);
|
||||
ShipmentModel pickupModel = Provider.of<ShipmentModel>(context);
|
||||
bool isLocalPickup = _shipment.shipmentType == shipment_local_pickup;
|
||||
bool isCourierPickup = _shipment.shipmentType == shipment_courier_pickup;
|
||||
bool isLocalDropoff = _shipment.shipmentType == shipment_local_dropoff;
|
||||
bool isCourierDropoff = _shipment.shipmentType == shipment_courier_dropoff;
|
||||
bool isEditable = widget.isCustomer
|
||||
? (_shipment.isPending || _shipment.isAssigned)
|
||||
: (_shipment.isPending || _shipment.isAssigned || _shipment.isPickuped);
|
||||
bool isLocalPickup = _shipment!.shipmentType == shipment_local_pickup;
|
||||
bool isCourierPickup = _shipment!.shipmentType == shipment_courier_pickup;
|
||||
bool isLocalDropoff = _shipment!.shipmentType == shipment_local_dropoff;
|
||||
bool isCourierDropoff = _shipment!.shipmentType == shipment_courier_dropoff;
|
||||
bool isEditable = widget.isCustomer!
|
||||
? (_shipment!.isPending || _shipment!.isAssigned)
|
||||
: (_shipment!.isPending ||
|
||||
_shipment!.isAssigned ||
|
||||
_shipment!.isPickuped);
|
||||
bool canCancel =
|
||||
_shipment.isPending || _shipment.isConfirmed || _shipment.isAssigned;
|
||||
_shipment!.isPending || _shipment!.isConfirmed || _shipment!.isAssigned;
|
||||
|
||||
final popupMenu = LocalPopupMenuButton(
|
||||
popmenus: [
|
||||
LocalPopupMenu(
|
||||
enabled: _shipment.isPending && isLocalPickup,
|
||||
enabled: _shipment!.isPending && isLocalPickup,
|
||||
id: 1,
|
||||
textKey: "shipment.assign.for.pickup",
|
||||
),
|
||||
LocalPopupMenu(
|
||||
enabled:
|
||||
(_shipment.isPickuped && isLocalPickup) || _shipment.isReceived,
|
||||
(_shipment!.isPickuped && isLocalPickup) || _shipment!.isReceived,
|
||||
id: 3,
|
||||
textKey: "shipment.pack.menuitem",
|
||||
),
|
||||
LocalPopupMenu(
|
||||
enabled: _shipment.isPending && (isCourierPickup || isCourierDropoff),
|
||||
enabled:
|
||||
_shipment!.isPending && (isCourierPickup || isCourierDropoff),
|
||||
id: 4,
|
||||
textKey: "shipment.confirm.menuitem",
|
||||
),
|
||||
@@ -149,7 +155,11 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
? _gotoAssign()
|
||||
: p.id == 2
|
||||
? _cancel()
|
||||
: p.id == 3 ? _gotoPack() : p.id == 4 ? _gotoConfirm() : null,
|
||||
: p.id == 3
|
||||
? _gotoPack()
|
||||
: p.id == 4
|
||||
? _gotoConfirm()
|
||||
: null,
|
||||
);
|
||||
final popupMenuCustomer = LocalPopupMenuButton(
|
||||
popmenus: [
|
||||
@@ -163,29 +173,31 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
buttonIcon: Icons.more_vert,
|
||||
popupMenuCallback: (p) => p.id == 2 ? _cancel() : null,
|
||||
);
|
||||
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment);
|
||||
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment!);
|
||||
|
||||
final fromTimeBox = DisplayText(
|
||||
labelTextKey: 'shipment.from',
|
||||
iconData: Icons.timer,
|
||||
text: _shipment.pickupTimeStart,
|
||||
text: _shipment!.pickupTimeStart ?? "",
|
||||
);
|
||||
final toTimeBox = DisplayText(
|
||||
labelTextKey: 'shipment.to',
|
||||
iconData: Icons.timer_off,
|
||||
text: _shipment.pickupTimeEnd,
|
||||
text: _shipment!.pickupTimeEnd ?? "",
|
||||
);
|
||||
|
||||
final pickupDateBox = DisplayText(
|
||||
labelTextKey: "shipment.date",
|
||||
iconData: Icons.date_range,
|
||||
text: dateFormatter.format(_shipment.pickupDate),
|
||||
text: _shipment!.pickupDate != null
|
||||
? dateFormatter.format(_shipment!.pickupDate!)
|
||||
: '',
|
||||
);
|
||||
var localDropoffAddressBox = Row(children: [
|
||||
FcsIDIcon(),
|
||||
Expanded(
|
||||
child: DisplayText(
|
||||
text: mainModel.setting.usaAddress,
|
||||
text: mainModel.setting!.usaAddress ?? "",
|
||||
),
|
||||
)
|
||||
]);
|
||||
@@ -201,17 +213,17 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
backgroundColor: Colors.white,
|
||||
));
|
||||
final pickupAddressBox = DefaultDeliveryAddress(
|
||||
deliveryAddress: _shipment.pickupAddress,
|
||||
deliveryAddress: _shipment!.pickupAddress,
|
||||
iconData: Icons.location_on,
|
||||
labelKey: "shipment.location",
|
||||
);
|
||||
var usersBox = DisplayText(
|
||||
labelTextKey: "shipment.staff",
|
||||
text: _shipment.pickupUserName,
|
||||
text: _shipment!.pickupUserName ?? "",
|
||||
iconData: MaterialCommunityIcons.worker);
|
||||
var handlingFeeBox = DisplayText(
|
||||
labelTextKey: "shipment.handling.fee",
|
||||
text: (_shipment.handlingFee ?? 0).toString(),
|
||||
text: (_shipment!.handlingFee ?? 0).toString(),
|
||||
iconData: FontAwesome.truck);
|
||||
|
||||
final assignCompleteBtn = LocalButton(
|
||||
@@ -232,7 +244,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
);
|
||||
|
||||
final fcsShipmentNumberBox = DisplayText(
|
||||
text: _shipment.fcsShipmentNumber,
|
||||
text: _shipment!.fcsShipmentNumber ?? "",
|
||||
labelTextKey: "FCSshipment.number",
|
||||
iconData: Ionicons.ios_airplane,
|
||||
);
|
||||
@@ -267,7 +279,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
color: isEditable ? primaryColor : Colors.grey),
|
||||
onPressed: isEditable ? _edit : null,
|
||||
),
|
||||
widget.isCustomer ? popupMenuCustomer : popupMenu,
|
||||
widget.isCustomer! ? popupMenuCustomer : popupMenu,
|
||||
]),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
@@ -278,7 +290,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
LocalRadioButtons(
|
||||
readOnly: true,
|
||||
values: pickupModel.shipmentTypes,
|
||||
selectedValue: _shipment.shipmentType,
|
||||
selectedValue: _shipment!.shipmentType,
|
||||
),
|
||||
...(isLocalDropoff
|
||||
? [
|
||||
@@ -305,13 +317,13 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
LocalTitle(
|
||||
textKey: "boxes.name",
|
||||
trailing: Text(
|
||||
"${_shipment.totalCount} Cartons - ${_shipment.totalWeight} lb"),
|
||||
"${_shipment!.totalCount} Cartons - ${_shipment!.totalWeight} lb"),
|
||||
),
|
||||
Column(
|
||||
children: getBoxList(context, _shipment.boxes),
|
||||
children: getBoxList(context, _shipment!.boxes),
|
||||
),
|
||||
!_isCustomer ? fcsShipmentNumberBox : Container(),
|
||||
...(!_shipment.isPending
|
||||
...(!_shipment!.isPending
|
||||
? [
|
||||
handlingFeeBox,
|
||||
]
|
||||
@@ -324,22 +336,22 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
: []),
|
||||
...(isLocalPickup && !_isCustomer
|
||||
? [
|
||||
_shipment.isPending ? assignCompleteBtn : Container(),
|
||||
_shipment.isAssigned ? completePickupBtn : Container(),
|
||||
_shipment.isPickuped ? completePackBtn : Container(),
|
||||
_shipment!.isPending ? assignCompleteBtn : Container(),
|
||||
_shipment!.isAssigned ? completePickupBtn : Container(),
|
||||
_shipment!.isPickuped ? completePackBtn : Container(),
|
||||
]
|
||||
: []),
|
||||
...((isCourierPickup || isCourierDropoff) && !_isCustomer
|
||||
? [
|
||||
_shipment.isPending ? confirmCompleteBtn : Container(),
|
||||
_shipment.isConfirmed ? completeReceiveBtn : Container(),
|
||||
_shipment.isReceived ? completePackBtn : Container(),
|
||||
_shipment!.isPending ? confirmCompleteBtn : Container(),
|
||||
_shipment!.isConfirmed ? completeReceiveBtn : Container(),
|
||||
_shipment!.isReceived ? completePackBtn : Container(),
|
||||
]
|
||||
: []),
|
||||
...((isLocalDropoff) && !_isCustomer
|
||||
? [
|
||||
_shipment.isPending ? completeReceiveBtn : Container(),
|
||||
_shipment.isReceived ? completePackBtn : Container(),
|
||||
_shipment!.isPending ? completeReceiveBtn : Container(),
|
||||
_shipment!.isReceived ? completePackBtn : Container(),
|
||||
]
|
||||
: []),
|
||||
],
|
||||
@@ -361,7 +373,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
}
|
||||
|
||||
_edit() async {
|
||||
bool updated = await Navigator.push<bool>(
|
||||
bool? updated = await Navigator.push<bool>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ShipmentEditor(
|
||||
@@ -369,8 +381,8 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
)),
|
||||
);
|
||||
if (updated ?? false) {
|
||||
await _loadShipment(_shipment.id);
|
||||
await _loadCartons(_shipment.id);
|
||||
await _loadShipment(_shipment!.id!);
|
||||
await _loadCartons(_shipment!.id!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,7 +399,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
try {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
await shipmentModel.cancelShipment(_shipment);
|
||||
await shipmentModel.cancelShipment(_shipment!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
@@ -400,11 +412,11 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
|
||||
_openCourierWebsite() {
|
||||
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
|
||||
launch("${mainModel.setting.courierWebsite}");
|
||||
launch("${mainModel.setting!.courierWebsite}");
|
||||
}
|
||||
|
||||
_gotoAssign() async {
|
||||
bool assigned = await Navigator.push<bool>(
|
||||
bool? assigned = await Navigator.push<bool>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ShipmentAssign(
|
||||
@@ -412,7 +424,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
)),
|
||||
);
|
||||
if (assigned ?? false) {
|
||||
await _loadShipment(_shipment.id);
|
||||
await _loadShipment(_shipment!.id!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,7 +441,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
try {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
await shipmentModel.completeAssignShipment(_shipment);
|
||||
await shipmentModel.completeAssignShipment(_shipment!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
@@ -453,7 +465,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
try {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
await shipmentModel.completePickupShipment(_shipment);
|
||||
await shipmentModel.completePickupShipment(_shipment!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
@@ -465,16 +477,16 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
}
|
||||
|
||||
_gotoPack() async {
|
||||
bool assigned = await Navigator.push<bool>(
|
||||
bool? assigned = await Navigator.push<bool>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ShipmentPack(
|
||||
shipment: _shipment,
|
||||
shipment: _shipment!,
|
||||
)),
|
||||
);
|
||||
if (assigned ?? false) {
|
||||
await _loadShipment(_shipment.id);
|
||||
await _loadCartons(_shipment.id);
|
||||
await _loadShipment(_shipment!.id!);
|
||||
await _loadCartons(_shipment!.id!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -491,7 +503,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
try {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
await shipmentModel.completePackShipment(_shipment);
|
||||
await shipmentModel.completePackShipment(_shipment!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
@@ -503,7 +515,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
}
|
||||
|
||||
_gotoConfirm() async {
|
||||
bool assigned = await Navigator.push<bool>(
|
||||
bool? assigned = await Navigator.push<bool>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ShipmentConfirm(
|
||||
@@ -511,7 +523,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
)),
|
||||
);
|
||||
if (assigned ?? false) {
|
||||
await _loadShipment(_shipment.id);
|
||||
await _loadShipment(_shipment!.id!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -528,7 +540,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
try {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
await shipmentModel.completeConfirmShipment(_shipment);
|
||||
await shipmentModel.completeConfirmShipment(_shipment!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
@@ -552,7 +564,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
try {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
await shipmentModel.completeReceiveShipment(_shipment);
|
||||
await shipmentModel.completeReceiveShipment(_shipment!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
|
||||
Reference in New Issue
Block a user