null safety
This commit is contained in:
@@ -17,11 +17,12 @@ import 'package:fcs/pages/widgets/my_data_table.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:provider/provider.dart';
|
||||
|
||||
class ShipmentBoxEditor extends StatefulWidget {
|
||||
final Carton box;
|
||||
final Carton? box;
|
||||
ShipmentBoxEditor({this.box});
|
||||
|
||||
@override
|
||||
@@ -33,9 +34,9 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
TextEditingController _widthCtl = new TextEditingController();
|
||||
TextEditingController _heightCtl = new TextEditingController();
|
||||
|
||||
Carton _box;
|
||||
Carton? _box;
|
||||
bool _isLoading = false;
|
||||
bool _isNew;
|
||||
late bool _isNew;
|
||||
double volumetricRatio = 0;
|
||||
double shipmentWeight = 0;
|
||||
|
||||
@@ -50,16 +51,16 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
if (widget.box != null) {
|
||||
_box = widget.box;
|
||||
_isNew = false;
|
||||
_lengthCtl.text = _box.length.toString();
|
||||
_widthCtl.text = _box.width.toString();
|
||||
_heightCtl.text = _box.height.toString();
|
||||
_lengthCtl.text = _box!.length != null ? _box!.length.toString() : '';
|
||||
_widthCtl.text = _box!.width != null ? _box!.width.toString() : '';
|
||||
_heightCtl.text = _box!.height != null ? _box!.height.toString() : '';
|
||||
} else {
|
||||
var shipmentModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
|
||||
_isNew = true;
|
||||
_box = Carton(cargoTypes: []);
|
||||
_box.deliveryAddress = shipmentModel.defalutAddress;
|
||||
_box!.deliveryAddress = shipmentModel.defalutAddress;
|
||||
|
||||
_lengthCtl.text = "12";
|
||||
_widthCtl.text = "12";
|
||||
@@ -151,10 +152,11 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
CargoType cargo = await Navigator.push<CargoType>(
|
||||
CargoType? cargo = await Navigator.push<CargoType>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => CargoTypeEditor()));
|
||||
if (cargo == null) return;
|
||||
_addCargo(cargo);
|
||||
}),
|
||||
),
|
||||
@@ -186,19 +188,19 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
shipmentWeightBox,
|
||||
LocalTitle(textKey: "shipment.box.delivery"),
|
||||
DefaultDeliveryAddress(
|
||||
deliveryAddress: _box.deliveryAddress,
|
||||
deliveryAddress: _box!.deliveryAddress,
|
||||
labelKey: "shipment.box.delivery",
|
||||
onTap: () async {
|
||||
DeliveryAddress d = await Navigator.push<DeliveryAddress>(
|
||||
DeliveryAddress? d = await Navigator.push<DeliveryAddress>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _box.deliveryAddress,
|
||||
deliveryAddress: _box!.deliveryAddress,
|
||||
user: mainModel.user)),
|
||||
);
|
||||
if (d == null) return;
|
||||
setState(() {
|
||||
_box.deliveryAddress = d;
|
||||
_box!.deliveryAddress = d;
|
||||
});
|
||||
}),
|
||||
createBtn
|
||||
@@ -210,25 +212,26 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
}
|
||||
|
||||
List<MyDataRow> getCargoRows(BuildContext context) {
|
||||
if (_box.cargoTypes == null) {
|
||||
if (_box!.cargoTypes == null) {
|
||||
return [];
|
||||
}
|
||||
double total = 0;
|
||||
var rows = _box.cargoTypes.map((c) {
|
||||
var rows = _box!.cargoTypes.map((c) {
|
||||
total += c.weight;
|
||||
return MyDataRow(
|
||||
onSelectChanged: (bool selected) async {
|
||||
CargoType cargo = await Navigator.push<CargoType>(
|
||||
CargoType? cargo = await Navigator.push<CargoType>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => CargoTypeEditor(
|
||||
cargo: c,
|
||||
)));
|
||||
if (cargo == null) return;
|
||||
_addCargo(cargo);
|
||||
},
|
||||
cells: [
|
||||
MyDataCell(new Text(
|
||||
c.name == null ? "" : c.name,
|
||||
c.name == null ? "" : c.name!,
|
||||
style: textStyle,
|
||||
)),
|
||||
MyDataCell(
|
||||
@@ -281,14 +284,14 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
_addCargo(CargoType cargo) {
|
||||
if (cargo == null) return;
|
||||
setState(() {
|
||||
_box.cargoTypes.remove(cargo);
|
||||
_box.cargoTypes.add(cargo);
|
||||
_box!.cargoTypes.remove(cargo);
|
||||
_box!.cargoTypes.add(cargo);
|
||||
});
|
||||
}
|
||||
|
||||
_removeCargo(CargoType cargo) {
|
||||
setState(() {
|
||||
_box.cargoTypes.remove(cargo);
|
||||
_box!.cargoTypes.remove(cargo);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -296,9 +299,9 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
double l = double.parse(_lengthCtl.text, (s) => 0);
|
||||
double w = double.parse(_widthCtl.text, (s) => 0);
|
||||
double h = double.parse(_heightCtl.text, (s) => 0);
|
||||
_box.length = l;
|
||||
_box.width = w;
|
||||
_box.height = h;
|
||||
_box!.length = l;
|
||||
_box!.width = w;
|
||||
_box!.height = h;
|
||||
Navigator.pop(context, _box);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user