null safety

This commit is contained in:
phyothandar
2021-09-10 12:00:08 +06:30
parent a144c945b6
commit 5e672937b5
67 changed files with 901 additions and 896 deletions

View File

@@ -29,7 +29,7 @@ import 'package:fcs/pages/widgets/local_title.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_vector_icons/flutter_vector_icons.dart';
import 'package:provider/provider.dart';
import 'cargo_type_addtion.dart';
import 'carton_cargo_table.dart';
@@ -40,7 +40,7 @@ import 'package_carton_editor.dart';
import 'widgets.dart';
class CartonEditor extends StatefulWidget {
final Carton box;
final Carton? box;
CartonEditor({this.box});
@override
@@ -54,29 +54,29 @@ class _CartonEditorState extends State<CartonEditor> {
DeliveryAddress _deliveryAddress = new DeliveryAddress();
List<CargoType> _cargoTypes = [];
Carton _carton;
Carton? _carton;
bool _isLoading = false;
bool _isNew;
User _user;
String _selectedCartonType;
bool _isNew = false;
User? _user;
String? _selectedCartonType;
double volumetricRatio = 0;
double shipmentWeight = 0;
FcsShipment _fcsShipment;
List<FcsShipment> _fcsShipments;
FcsShipment? _fcsShipment;
List<FcsShipment>? _fcsShipments;
List<Carton> _cartons = [];
CartonSize selectedCatonSize;
CartonSize? selectedCatonSize;
//for mix carton
List<Carton> _mixCartons = [];
String _selectedMixBoxType;
String? _selectedMixBoxType;
//for carton from cargos
User consignee;
User sender;
User? consignee;
User? sender;
List<Carton> _cartonsFromCartons = [];
double totalWeight;
double? totalWeight;
@override
void initState() {
@@ -92,28 +92,28 @@ class _CartonEditorState extends State<CartonEditor> {
if (widget.box != null) {
_carton = widget.box;
_deliveryAddress = _carton.deliveryAddress;
_widthController.text = _carton.width.toString();
_heightController.text = _carton.height.toString();
_lengthController.text = _carton.length.toString();
_selectedCartonType = _carton.cartonType;
_deliveryAddress = _carton!.deliveryAddress;
_widthController.text = _carton!.width.toString();
_heightController.text = _carton!.height.toString();
_lengthController.text = _carton!.length.toString();
_selectedCartonType = _carton!.cartonType;
_cargoTypes = _carton.cargoTypes.map((e) => e.clone()).toList();
_cargoTypes = _carton!.cargoTypes.map((e) => e.clone()).toList();
_isNew = false;
_user = User(
id: _carton.userID, fcsID: _carton.fcsID, name: _carton.userName);
id: _carton!.userID, fcsID: _carton!.fcsID, name: _carton!.userName);
consignee = User(
id: _carton.userID, fcsID: _carton.fcsID, name: _carton.userName);
id: _carton!.userID, fcsID: _carton!.fcsID, name: _carton!.userName);
sender = User(
id: _carton.senderID,
fcsID: _carton.senderFCSID,
name: _carton.senderName);
_selectedMixBoxType = _carton.mixBoxType ?? "";
id: _carton!.senderID,
fcsID: _carton!.senderFCSID,
name: _carton!.senderName);
_selectedMixBoxType = _carton!.mixBoxType;
this._mixCartons =
_carton.mixCartons == null ? [] : List.from(_carton.mixCartons);
bool isMixBox = _carton.cartonType == carton_mix_box;
bool isFromPackages = _carton.cartonType == carton_from_packages;
_carton!.mixCartons == null ? [] : List.from(_carton!.mixCartons);
bool isMixBox = _carton!.cartonType == carton_mix_box;
bool isFromPackages = _carton!.cartonType == carton_from_packages;
if (isFromPackages) _loadPackages();
if (!isMixBox) {
@@ -138,8 +138,8 @@ 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, orElse: () => null);
var fcsShipment =
fcsShipments.firstWhere((e) => e.id == _carton!.fcsShipmentID);
setState(() {
_fcsShipments = fcsShipments;
_fcsShipment = fcsShipment;
@@ -151,12 +151,12 @@ class _CartonEditorState extends State<CartonEditor> {
PackageModel packageModel =
Provider.of<PackageModel>(context, listen: false);
List<Package> packages = await packageModel.getPackages(
_user.id, [package_processed_status, package_packed_status]);
_user!.id, [package_processed_status, package_packed_status]);
if (_isNew) {
String prevCompare;
String? prevCompare;
packages.forEach((p) {
String compare = (p.deliveryAddress?.fullName ?? "") +
(p.deliveryAddress?.phoneNumber ?? "");
String compare =
(p.deliveryAddress.fullName) + (p.deliveryAddress.phoneNumber);
if (prevCompare != null && compare == prevCompare) {
p.isChecked = true;
} else {
@@ -169,8 +169,8 @@ class _CartonEditorState extends State<CartonEditor> {
});
} else {
packages.forEach((p) {
if (_carton.packages.contains(p)) {
p.isChecked = _carton.packages.firstWhere((cp) => cp == p).isChecked;
if (_carton!.packages.contains(p)) {
p.isChecked = _carton!.packages.firstWhere((cp) => cp == p).isChecked;
} else {
p.isChecked = false;
}
@@ -178,7 +178,7 @@ class _CartonEditorState extends State<CartonEditor> {
}
setState(() {
_carton.packages = packages;
_carton!.packages = packages;
});
// _populateDeliveryAddress();
}
@@ -206,9 +206,9 @@ class _CartonEditorState extends State<CartonEditor> {
_getCartonSize() {
var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false);
cartonSizeModel.cartonSizes.forEach((c) {
if (c.length == _carton.length &&
c.width == _carton.width &&
c.height == _carton.height) {
if (c.length == _carton!.length &&
c.width == _carton!.width &&
c.height == _carton!.height) {
selectedCatonSize = CartonSize(
id: c.id,
name: c.name,
@@ -232,7 +232,7 @@ class _CartonEditorState extends State<CartonEditor> {
bool isMixBox = _selectedCartonType == carton_mix_box;
final shipmentBox = DisplayText(
text: _carton.fcsShipmentNumber,
text: _carton!.fcsShipmentNumber,
labelTextKey: "box.fcs_shipment_num",
iconData: Ionicons.ios_airplane,
);
@@ -248,8 +248,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(
@@ -297,7 +297,7 @@ class _CartonEditorState extends State<CartonEditor> {
readOnly: !_isNew,
values: boxModel.cartonTypes,
selectedValue: _selectedCartonType,
callback: (v) {
callback: (String? v) {
setState(() {
_selectedCartonType = v;
});
@@ -337,7 +337,7 @@ class _CartonEditorState extends State<CartonEditor> {
value: e,
groupValue: _selectedMixBoxType,
activeColor: primaryColor,
onChanged: (v) {
onChanged: (String? v) {
setState(() {
_selectedMixBoxType = v;
});
@@ -407,7 +407,7 @@ class _CartonEditorState extends State<CartonEditor> {
color: primaryColor,
),
onPressed: () async {
List<CargoType> cargos = await Navigator.push<List<CargoType>>(
List<CargoType>? cargos = await Navigator.push<List<CargoType>>(
context,
CupertinoPageRoute(builder: (context) => CargoTypeAddition()));
if (cargos == null) return;
@@ -462,7 +462,7 @@ class _CartonEditorState extends State<CartonEditor> {
children: <Widget>[
Expanded(
child: DisplayText(
text: consignee != null ? consignee.fcsID : "",
text: consignee != null ? consignee!.fcsID : "",
labelTextKey: "processing.fcs.id",
icon: FcsIDIcon(),
)),
@@ -477,7 +477,7 @@ class _CartonEditorState extends State<CartonEditor> {
);
final consigneeNameBox = DisplayText(
text: consignee != null ? consignee.name : "",
text: consignee != null ? consignee!.name : "",
labelTextKey: "processing.consignee.name",
maxLines: 2,
iconData: Icons.person,
@@ -496,7 +496,7 @@ class _CartonEditorState extends State<CartonEditor> {
children: <Widget>[
Expanded(
child: DisplayText(
text: sender != null ? sender.fcsID : "",
text: sender != null ? sender!.fcsID : "",
labelTextKey: "processing.fcs.id",
icon: FcsIDIcon(),
)),
@@ -511,7 +511,7 @@ class _CartonEditorState extends State<CartonEditor> {
);
final shipperNamebox = DisplayText(
text: sender != null ? sender.name : "",
text: sender != null ? sender!.name : "",
labelTextKey: "processing.shipper.name",
maxLines: 2,
iconData: Icons.person,
@@ -551,7 +551,7 @@ class _CartonEditorState extends State<CartonEditor> {
children: [
_isNew
? Container()
: Center(child: getCartonNumberStatus(context, _carton)),
: Center(child: getCartonNumberStatus(context, _carton!)),
LocalTitle(textKey: "box.type.title"),
cartonTypeBox,
LocalTitle(textKey: "box.shipment_info"),
@@ -572,7 +572,7 @@ class _CartonEditorState extends State<CartonEditor> {
isFromPackages ? namebox : Container(),
isFromPackages
? CartonPackageTable(
packages: _carton.packages,
packages: _carton!.packages,
onSelect: (p, checked) {
// if (checked &&
// _deliveryAddress != null &&
@@ -623,7 +623,7 @@ class _CartonEditorState extends State<CartonEditor> {
deliveryAddress: _deliveryAddress,
labelKey: "box.delivery_address",
onTap: () async {
DeliveryAddress d =
DeliveryAddress? d =
await Navigator.push<DeliveryAddress>(
context,
CupertinoPageRoute(
@@ -631,8 +631,8 @@ class _CartonEditorState extends State<CartonEditor> {
DeliveryAddressSelection(
deliveryAddress: _deliveryAddress,
user: User(
id: _carton.userID,
name: _carton.userName))),
id: _carton!.userID,
name: _carton!.userName))),
);
if (d == null) return;
setState(() {
@@ -667,7 +667,7 @@ class _CartonEditorState extends State<CartonEditor> {
bool isFromCartons = _selectedCartonType == carton_from_cartons;
if (isFromPackages) {
_loadPackages();
c.value.packages = _carton.packages;
c.value.packages = _carton!.packages;
Carton _c = await Navigator.push(
context,
CupertinoPageRoute(
@@ -736,20 +736,20 @@ class _CartonEditorState extends State<CartonEditor> {
height: 1,
color: Colors.grey,
),
onChanged: (CartonSize newValue) {
onChanged: (CartonSize? newValue) {
setState(() {
if (newValue.name == MANAGE_CARTONSIZE) {
if (newValue!.name == MANAGE_CARTONSIZE) {
selectedCatonSize = null;
_manageCartonSize();
return;
}
selectedCatonSize = newValue;
_widthController.text =
selectedCatonSize.width.toString();
selectedCatonSize!.width.toString();
_heightController.text =
selectedCatonSize.height.toString();
selectedCatonSize!.height.toString();
_lengthController.text =
selectedCatonSize.length.toString();
selectedCatonSize!.length.toString();
});
},
isExpanded: true,
@@ -757,7 +757,7 @@ class _CartonEditorState extends State<CartonEditor> {
.map<DropdownMenuItem<CartonSize>>((CartonSize value) {
return DropdownMenuItem<CartonSize>(
value: value,
child: Text(value.name ?? "",
child: Text(value.name,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: value.name == MANAGE_CARTONSIZE
@@ -789,8 +789,7 @@ class _CartonEditorState extends State<CartonEditor> {
_updateCargo(CargoType cargo) {
setState(() {
var _c =
_cargoTypes.firstWhere((e) => e.id == cargo.id, orElse: () => null);
var _c = _cargoTypes.firstWhere((e) => e.id == cargo.id);
if (_c != null) {
_c.weight = cargo.weight;
_c.qty = cargo.qty;
@@ -827,30 +826,30 @@ class _CartonEditorState extends State<CartonEditor> {
double h = double.parse(_heightController.text, (s) => 0);
Carton carton = Carton();
carton.id = _carton.id;
carton.cartonType = _selectedCartonType;
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
carton.id = _carton!.id;
carton.cartonType = _selectedCartonType!;
carton.fcsShipmentID = _isNew ? _fcsShipment!.id : _carton!.fcsShipmentID;
if (isFromPackages) {
carton.userID = _user?.id;
carton.fcsID = _user?.fcsID;
carton.userName = _user?.name;
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
carton.userID = _user?.id ?? '';
carton.fcsID = _user?.fcsID ?? '';
carton.userName = _user?.name ?? '';
carton.packages = _carton!.packages.where((e) => e.isChecked).toList();
}
if (isFromCartons) {
carton.userID = consignee?.id;
carton.fcsID = consignee?.fcsID;
carton.userName = consignee?.name;
carton.senderID = sender?.id;
carton.senderFCSID = sender?.fcsID;
carton.senderName = sender?.name;
carton.userID = consignee?.id ?? "";
carton.fcsID = consignee?.fcsID ?? "";
carton.userName = consignee?.name ?? "";
carton.senderID = sender?.id ?? "";
carton.senderFCSID = sender?.fcsID ?? "";
carton.senderName = sender?.name ?? "";
}
carton.cargoTypes = _carton.cargoTypes;
carton.cargoTypes = _carton!.cargoTypes;
carton.length = l;
carton.width = w;
carton.height = h;
carton.deliveryAddress = _carton.deliveryAddress;
carton.deliveryAddress = _carton!.deliveryAddress;
try {
Carton _c = await Navigator.push(
@@ -898,15 +897,15 @@ class _CartonEditorState extends State<CartonEditor> {
showMsgDialog(context, "Error", "Please select FCS shipment");
return;
}
if ((this._mixCartons?.length ?? 0) == 0) {
if (this._mixCartons.length == 0) {
showMsgDialog(context, "Error", "Expect at least one carton");
return;
}
Carton carton = Carton();
carton.id = _carton.id;
carton.cartonType = _selectedCartonType;
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
carton.mixBoxType = _selectedMixBoxType;
carton.id = _carton!.id;
carton.cartonType = _selectedCartonType!;
carton.fcsShipmentID = _isNew ? _fcsShipment!.id : _carton!.fcsShipmentID;
carton.mixBoxType = _selectedMixBoxType!;
carton.mixCartons = this._mixCartons;
setState(() {
_isLoading = true;
@@ -932,11 +931,11 @@ class _CartonEditorState extends State<CartonEditor> {
_save() async {
bool isFromPackages = _selectedCartonType == carton_from_packages;
bool isFromCartons = _selectedCartonType == carton_from_cartons;
if ((_cargoTypes?.length ?? 0) == 0 && (isFromPackages || isFromCartons)) {
if (_cargoTypes.length == 0 && (isFromPackages || isFromCartons)) {
showMsgDialog(context, "Error", "Expect at least one cargo type");
return;
}
if (_cargoTypes.where((c) => c.weight <= 0).isNotEmpty) {
if (_cargoTypes.where((c) => c.weight! <= 0).isNotEmpty) {
showMsgDialog(context, "Error", "Invalid cargo weight");
return;
}
@@ -953,16 +952,16 @@ class _CartonEditorState extends State<CartonEditor> {
}
Carton carton = Carton();
carton.id = _carton.id;
carton.cartonType = _selectedCartonType;
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
carton.id = _carton!.id;
carton.cartonType = _selectedCartonType!;
carton.fcsShipmentID = _isNew ? _fcsShipment!.id : _carton!.fcsShipmentID;
if (isFromPackages) {
carton.userID = _user?.id;
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
carton.userID = _user?.id ?? "";
carton.packages = _carton!.packages.where((e) => e.isChecked).toList();
}
if (isFromCartons) {
carton.userID = consignee?.id;
carton.senderID = sender?.id;
carton.userID = consignee?.id ?? "";
carton.senderID = sender?.id ?? "";
}
carton.cargoTypes = _cargoTypes;