null safety
This commit is contained in:
@@ -19,7 +19,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:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -33,7 +33,7 @@ import 'widgets.dart';
|
||||
final DateFormat dateFormat = DateFormat("d MMM yyyy");
|
||||
|
||||
class CartonInfo extends StatefulWidget {
|
||||
final Carton box;
|
||||
final Carton? box;
|
||||
CartonInfo({this.box});
|
||||
|
||||
@override
|
||||
@@ -42,7 +42,7 @@ class CartonInfo extends StatefulWidget {
|
||||
|
||||
class _CartonInfoState extends State<CartonInfo> {
|
||||
bool _isLoading = false;
|
||||
Carton _box;
|
||||
Carton? _box;
|
||||
DeliveryAddress _deliveryAddress = new DeliveryAddress();
|
||||
TextEditingController _widthController = new TextEditingController();
|
||||
TextEditingController _heightController = new TextEditingController();
|
||||
@@ -50,14 +50,14 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
TextEditingController _cartonSizeController = new TextEditingController();
|
||||
double volumetricRatio = 0;
|
||||
double shipmentWeight = 0;
|
||||
String selectMixBoxType;
|
||||
String? selectMixBoxType;
|
||||
|
||||
bool isMixBox;
|
||||
bool isFromShipments;
|
||||
bool isFromPackages;
|
||||
bool isSmallBag;
|
||||
bool isFromCartons;
|
||||
bool isEdiable;
|
||||
bool isMixBox = false;
|
||||
bool isFromShipments = false;
|
||||
bool isFromPackages = false;
|
||||
bool isSmallBag = false;
|
||||
bool isFromCartons = false;
|
||||
bool isEdiable = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -77,29 +77,29 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
}
|
||||
|
||||
_updateBoxData() {
|
||||
_widthController.text = _box.width.toString();
|
||||
_heightController.text = _box.height.toString();
|
||||
_lengthController.text = _box.length.toString();
|
||||
_cartonSizeController.text = _box.cartonSizeName ?? "";
|
||||
_deliveryAddress = _box.deliveryAddress;
|
||||
isMixBox = _box.cartonType == carton_mix_box;
|
||||
isFromShipments = _box.cartonType == carton_from_shipments;
|
||||
isFromPackages = _box.cartonType == carton_from_packages;
|
||||
isSmallBag = _box.cartonType == carton_small_bag;
|
||||
isFromCartons = _box.cartonType == carton_from_cartons;
|
||||
_widthController.text = _box!.width.toString();
|
||||
_heightController.text = _box!.height.toString();
|
||||
_lengthController.text = _box!.length.toString();
|
||||
_cartonSizeController.text = _box!.cartonSizeName;
|
||||
_deliveryAddress = _box!.deliveryAddress;
|
||||
isMixBox = _box!.cartonType == carton_mix_box;
|
||||
isFromShipments = _box!.cartonType == carton_from_shipments;
|
||||
isFromPackages = _box!.cartonType == carton_from_packages;
|
||||
isSmallBag = _box!.cartonType == carton_small_bag;
|
||||
isFromCartons = _box!.cartonType == carton_from_cartons;
|
||||
|
||||
isEdiable = (isFromPackages || isMixBox || isFromCartons) &&
|
||||
_box.status == carton_packed_status;
|
||||
selectMixBoxType = _box.mixBoxType ?? "";
|
||||
_box!.status == carton_packed_status;
|
||||
selectMixBoxType = _box!.mixBoxType;
|
||||
getCartonSize();
|
||||
}
|
||||
|
||||
getCartonSize() {
|
||||
var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false);
|
||||
cartonSizeModel.cartonSizes.forEach((c) {
|
||||
if (c.length == _box.length &&
|
||||
c.width == _box.width &&
|
||||
c.height == _box.height) {
|
||||
if (c.length == _box!.length &&
|
||||
c.width == _box!.width &&
|
||||
c.height == _box!.height) {
|
||||
setState(() {
|
||||
_cartonSizeController.text = c.name;
|
||||
});
|
||||
@@ -110,36 +110,37 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
_loadPackages() async {
|
||||
if (!isFromPackages && !isSmallBag) return;
|
||||
|
||||
if (_box.cartonType == carton_from_packages && _box.userID == null) return;
|
||||
if (_box!.cartonType == carton_from_packages && _box!.userID == null)
|
||||
return;
|
||||
PackageModel packageModel =
|
||||
Provider.of<PackageModel>(context, listen: false);
|
||||
List<Package> packages = await packageModel.getPackages(_box.userID, [
|
||||
List<Package> packages = await packageModel.getPackages(_box!.userID, [
|
||||
package_processed_status,
|
||||
package_packed_status,
|
||||
package_shipped_status,
|
||||
package_delivered_status
|
||||
]);
|
||||
packages = packages.where((p) => _box.packageIDs.contains(p.id)).toList();
|
||||
packages = packages.where((p) => _box!.packageIDs.contains(p.id)).toList();
|
||||
packages.forEach((p) {
|
||||
p.isChecked = true;
|
||||
});
|
||||
|
||||
setState(() {
|
||||
_box.packages = packages;
|
||||
_box!.packages = packages;
|
||||
});
|
||||
}
|
||||
|
||||
_loadMixCartons() async {
|
||||
if (_box.cartonType != carton_mix_box) return;
|
||||
if (_box!.cartonType != carton_mix_box) return;
|
||||
CartonModel cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
List<Carton> catons = [];
|
||||
for (var id in _box.mixCartonIDs) {
|
||||
for (var id in _box!.mixCartonIDs) {
|
||||
Carton c = await cartonModel.getCarton(id);
|
||||
catons.add(c);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_box.mixCartons = catons;
|
||||
_box!.mixCartons = catons;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -167,32 +168,32 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
readOnly: true,
|
||||
values: cartonModel.cartonTypesInfo,
|
||||
selectedValue:
|
||||
_box.isShipmentCarton ? carton_from_shipments : _box.cartonType);
|
||||
_box!.isShipmentCarton ? carton_from_shipments : _box!.cartonType);
|
||||
final shipmentBox = DisplayText(
|
||||
text: _box.fcsShipmentNumber,
|
||||
text: _box!.fcsShipmentNumber,
|
||||
labelTextKey: "box.fcs_shipment_num",
|
||||
iconData: Ionicons.ios_airplane,
|
||||
);
|
||||
final fcsIDBox = DisplayText(
|
||||
text: _box.fcsID == null ? "" : _box.fcsID,
|
||||
text: _box!.fcsID == null ? "" : _box!.fcsID,
|
||||
labelTextKey: "box.fcs.id",
|
||||
icon: FcsIDIcon(),
|
||||
);
|
||||
|
||||
final customerNameBox = DisplayText(
|
||||
text: _box.userName == null ? "" : _box.userName,
|
||||
text: _box!.userName == null ? "" : _box!.userName,
|
||||
labelTextKey: "box.name",
|
||||
iconData: Icons.person,
|
||||
);
|
||||
|
||||
final consigneefcsIDBox = DisplayText(
|
||||
text: _box.fcsID != null ? _box.fcsID : "",
|
||||
text: _box!.fcsID != null ? _box!.fcsID : "",
|
||||
labelTextKey: "processing.fcs.id",
|
||||
icon: FcsIDIcon(),
|
||||
);
|
||||
|
||||
final consigneeNameBox = DisplayText(
|
||||
text: _box.userName != null ? _box.userName : "",
|
||||
text: _box!.userName != null ? _box!.userName : "",
|
||||
labelTextKey: "processing.consignee.name",
|
||||
maxLines: 2,
|
||||
iconData: Icons.person,
|
||||
@@ -211,7 +212,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: DisplayText(
|
||||
text: _box.senderFCSID != null ? _box.senderFCSID : "",
|
||||
text: _box!.senderFCSID,
|
||||
labelTextKey: "processing.fcs.id",
|
||||
icon: FcsIDIcon(),
|
||||
)),
|
||||
@@ -219,7 +220,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
);
|
||||
|
||||
final shipperNamebox = DisplayText(
|
||||
text: _box.senderName != null ? _box.senderName : "",
|
||||
text: _box!.senderName,
|
||||
labelTextKey: "processing.shipper.name",
|
||||
maxLines: 2,
|
||||
iconData: Icons.person,
|
||||
@@ -269,10 +270,10 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
iconData: AntDesign.CodeSandbox,
|
||||
);
|
||||
final cargoTableBox = CargoTable(
|
||||
cargoTypes: _box.cargoTypes,
|
||||
cargoTypes: _box!.cargoTypes,
|
||||
);
|
||||
final mixCartonNumberBox = DisplayText(
|
||||
text: _box.mixCartonNumber,
|
||||
text: _box!.mixCartonNumber,
|
||||
labelTextKey: "box.mix.carton",
|
||||
iconData: MaterialCommunityIcons.package,
|
||||
);
|
||||
@@ -300,7 +301,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
color: primaryColor,
|
||||
),
|
||||
),
|
||||
Text(selectMixBoxType)
|
||||
Text(selectMixBoxType ?? "")
|
||||
],
|
||||
)
|
||||
],
|
||||
@@ -340,7 +341,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: ListView(shrinkWrap: true, children: <Widget>[
|
||||
Center(child: getCartonNumberStatus(context, _box)),
|
||||
Center(child: getCartonNumberStatus(context, _box!)),
|
||||
LocalTitle(textKey: "box.type.title"),
|
||||
cartonTypeBox,
|
||||
LocalTitle(textKey: "box.shipment_info"),
|
||||
@@ -367,11 +368,11 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
isMixBox ? mixTypeBox : Container(),
|
||||
isMixBox ? LocalTitle(textKey: "box.mix_caton_title") : Container(),
|
||||
isMixBox
|
||||
? Column(children: _getCartons(context, _box.mixCartons))
|
||||
? Column(children: _getCartons(context, _box!.mixCartons))
|
||||
: Container(),
|
||||
isFromPackages || isSmallBag
|
||||
? CartonPackageTable(
|
||||
packages: _box.packages,
|
||||
packages: _box!.packages,
|
||||
)
|
||||
: Container(),
|
||||
isMixBox ? Container() : LocalTitle(textKey: "box.cargo.type"),
|
||||
@@ -408,14 +409,14 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
}
|
||||
|
||||
_gotoEditor() async {
|
||||
_box.mixCartons = _box.mixCartons;
|
||||
bool updated = await Navigator.push<bool>(
|
||||
_box!.mixCartons = _box!.mixCartons;
|
||||
bool? updated = await Navigator.push<bool>(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => CartonEditor(box: _box)),
|
||||
);
|
||||
if (updated ?? false) {
|
||||
var cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
var c = await cartonModel.getCarton(widget.box.id);
|
||||
var c = await cartonModel.getCarton(widget.box!.id);
|
||||
setState(() {
|
||||
_box = c;
|
||||
_loadPackages();
|
||||
@@ -437,7 +438,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
});
|
||||
try {
|
||||
var cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
await cartonModel.deleteCarton(widget.box);
|
||||
await cartonModel.deleteCarton(widget.box!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
|
||||
Reference in New Issue
Block a user