null safety
This commit is contained in:
@@ -21,7 +21,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';
|
||||
@@ -29,9 +29,9 @@ import 'carton_cargo_table.dart';
|
||||
import 'model/carton_model.dart';
|
||||
|
||||
class PackageCartonEditor extends StatefulWidget {
|
||||
final Carton carton;
|
||||
final bool isNew;
|
||||
final User consignee;
|
||||
final Carton? carton;
|
||||
final bool? isNew;
|
||||
final User? consignee;
|
||||
PackageCartonEditor({this.carton, this.isNew, this.consignee});
|
||||
|
||||
@override
|
||||
@@ -43,13 +43,13 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
TextEditingController _widthCtl = new TextEditingController();
|
||||
TextEditingController _heightCtl = new TextEditingController();
|
||||
|
||||
Carton _carton;
|
||||
Carton? _carton;
|
||||
bool _isLoading = false;
|
||||
DeliveryAddress _deliveryAddress = new DeliveryAddress();
|
||||
List<CargoType> _cargoTypes = [];
|
||||
CartonSize selectedCatonSize;
|
||||
bool isFromPackages;
|
||||
bool isFromCartons;
|
||||
CartonSize? selectedCatonSize;
|
||||
bool isFromPackages = false;
|
||||
bool isFromCartons = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -59,19 +59,19 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
|
||||
_load() {
|
||||
_carton = widget.carton;
|
||||
isFromPackages = _carton.cartonType == carton_from_packages;
|
||||
isFromCartons = _carton.cartonType == carton_from_cartons;
|
||||
isFromPackages = _carton!.cartonType == carton_from_packages;
|
||||
isFromCartons = _carton!.cartonType == carton_from_cartons;
|
||||
|
||||
if (widget.isNew) {
|
||||
if (widget.isNew!) {
|
||||
_lengthCtl.text = "0";
|
||||
_widthCtl.text = "0";
|
||||
_heightCtl.text = "0";
|
||||
} else {
|
||||
_cargoTypes = widget.carton.cargoTypes.map((e) => e.clone()).toList();
|
||||
_lengthCtl.text = _carton.length.toString();
|
||||
_widthCtl.text = _carton.width.toString();
|
||||
_heightCtl.text = _carton.height.toString();
|
||||
_deliveryAddress = _carton.deliveryAddress;
|
||||
_cargoTypes = widget.carton!.cargoTypes.map((e) => e.clone()).toList();
|
||||
_lengthCtl.text = _carton!.length.toString();
|
||||
_widthCtl.text = _carton!.width.toString();
|
||||
_heightCtl.text = _carton!.height.toString();
|
||||
_deliveryAddress = _carton!.deliveryAddress;
|
||||
_getCartonSize();
|
||||
}
|
||||
}
|
||||
@@ -79,9 +79,9 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
_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,
|
||||
@@ -122,7 +122,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
],
|
||||
);
|
||||
final createBtn = LocalButton(
|
||||
textKey: widget.isNew ? "box.new_carton_btn" : "box.cargo.save.btn",
|
||||
textKey: widget.isNew! ? "box.new_carton_btn" : "box.cargo.save.btn",
|
||||
callBack: _creatCarton,
|
||||
);
|
||||
|
||||
@@ -134,11 +134,10 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
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;
|
||||
if (cargos == null) return;
|
||||
setState(() {
|
||||
_cargoTypes.addAll(
|
||||
cargos.where((e) => !_cargoTypes.contains(e)).toList());
|
||||
@@ -168,7 +167,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
backgroundColor: Colors.white,
|
||||
title: LocalText(
|
||||
context,
|
||||
widget.isNew ? "boxes.create.title" : "box.edit.title",
|
||||
widget.isNew! ? "boxes.create.title" : "box.edit.title",
|
||||
fontSize: 20,
|
||||
color: primaryColor,
|
||||
),
|
||||
@@ -187,13 +186,14 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
deliveryAddress: _deliveryAddress,
|
||||
labelKey: "box.delivery_address",
|
||||
onTap: () async {
|
||||
DeliveryAddress d = await Navigator.push<DeliveryAddress>(
|
||||
DeliveryAddress? d = await Navigator.push<DeliveryAddress>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
user: User(
|
||||
id: _carton.userID, name: _carton.userName),
|
||||
id: _carton!.userID,
|
||||
name: _carton!.userName),
|
||||
)),
|
||||
);
|
||||
if (d == null) return;
|
||||
@@ -245,17 +245,17 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
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;
|
||||
_widthCtl.text = selectedCatonSize.width.toString();
|
||||
_heightCtl.text = selectedCatonSize.height.toString();
|
||||
_lengthCtl.text = selectedCatonSize.length.toString();
|
||||
_widthCtl.text = selectedCatonSize!.width.toString();
|
||||
_heightCtl.text = selectedCatonSize!.height.toString();
|
||||
_lengthCtl.text = selectedCatonSize!.length.toString();
|
||||
});
|
||||
},
|
||||
isExpanded: true,
|
||||
@@ -263,7 +263,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
.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
|
||||
@@ -295,8 +295,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
|
||||
_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;
|
||||
@@ -305,13 +304,13 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
}
|
||||
|
||||
_creatCarton() async {
|
||||
if ((_cargoTypes?.length ?? 0) == 0) {
|
||||
if (_cargoTypes.length == 0) {
|
||||
showMsgDialog(context, "Error", "Expect at least one cargo type");
|
||||
return;
|
||||
}
|
||||
double l = double.parse(_lengthCtl.text, (s) => 0);
|
||||
double w = double.parse(_widthCtl.text, (s) => 0);
|
||||
double h = double.parse(_heightCtl.text, (s) => 0);
|
||||
double l = double.parse(_lengthCtl.text);
|
||||
double w = double.parse(_widthCtl.text);
|
||||
double h = double.parse(_heightCtl.text);
|
||||
if ((l <= 0 || w <= 0 || h <= 0)) {
|
||||
showMsgDialog(context, "Error", "Invalid dimension");
|
||||
return;
|
||||
@@ -322,22 +321,22 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
}
|
||||
|
||||
Carton carton = Carton();
|
||||
carton.id = _carton.id;
|
||||
carton.cartonType = _carton.cartonType;
|
||||
carton.fcsShipmentID = _carton.fcsShipmentID;
|
||||
carton.id = _carton!.id;
|
||||
carton.cartonType = _carton!.cartonType;
|
||||
carton.fcsShipmentID = _carton!.fcsShipmentID;
|
||||
carton.cargoTypes = _cargoTypes;
|
||||
if (isFromPackages) {
|
||||
carton.userID = _carton.userID;
|
||||
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
carton.userID = _carton!.userID;
|
||||
carton.packages = _carton!.packages.where((e) => e.isChecked).toList();
|
||||
}
|
||||
|
||||
if (isFromCartons) {
|
||||
carton.userID = _carton.userID;
|
||||
carton.fcsID = _carton.fcsID;
|
||||
carton.userName = _carton.userName;
|
||||
carton.senderID = _carton.senderID;
|
||||
carton.senderFCSID = _carton.senderFCSID;
|
||||
carton.senderName = _carton.senderName;
|
||||
carton.userID = _carton!.userID;
|
||||
carton.fcsID = _carton!.fcsID;
|
||||
carton.userName = _carton!.userName;
|
||||
carton.senderID = _carton!.senderID;
|
||||
carton.senderFCSID = _carton!.senderFCSID;
|
||||
carton.senderName = _carton!.senderName;
|
||||
}
|
||||
|
||||
carton.length = l;
|
||||
@@ -350,12 +349,12 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
try {
|
||||
CartonModel cartonModel =
|
||||
Provider.of<CartonModel>(context, listen: false);
|
||||
if (widget.isNew) {
|
||||
if (widget.isNew!) {
|
||||
Carton _c = await cartonModel.createCarton(carton);
|
||||
Navigator.pop(context, _c);
|
||||
} else {
|
||||
await cartonModel.updateCarton(carton);
|
||||
Carton _c = await cartonModel.getCarton(_carton.id);
|
||||
Carton _c = await cartonModel.getCarton(_carton!.id);
|
||||
Navigator.pop(context, _c);
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user