null safety
This commit is contained in:
@@ -5,7 +5,7 @@ import 'package:flutter/material.dart';
|
||||
class BoxRow extends StatelessWidget {
|
||||
final Carton box;
|
||||
|
||||
const BoxRow({Key key, this.box}) : super(key: key);
|
||||
const BoxRow({Key? key, required this.box}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import 'package:logging/logging.dart';
|
||||
class ShipmentModel extends BaseModel {
|
||||
final log = Logger('ShipmentModel');
|
||||
|
||||
StreamSubscription<QuerySnapshot> listener;
|
||||
StreamSubscription<QuerySnapshot>? listener;
|
||||
|
||||
List<Shipment> get shipments => _menuSelectedIndex == 1
|
||||
? _shipments
|
||||
@@ -19,7 +19,7 @@ class ShipmentModel extends BaseModel {
|
||||
|
||||
List<Shipment> _shipments = [];
|
||||
|
||||
Paginator _delivered;
|
||||
late Paginator _delivered;
|
||||
bool isLoading = false;
|
||||
int _menuSelectedIndex = 1;
|
||||
|
||||
@@ -28,7 +28,7 @@ class ShipmentModel extends BaseModel {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
get menuSelectedIndex => _menuSelectedIndex;
|
||||
int get menuSelectedIndex => _menuSelectedIndex;
|
||||
|
||||
initData(bool forCustomer, {bool myPickup = false}) {
|
||||
logout();
|
||||
@@ -43,11 +43,11 @@ class ShipmentModel extends BaseModel {
|
||||
@override
|
||||
logout() async {
|
||||
if (_delivered != null) _delivered.close();
|
||||
if (listener != null) await listener.cancel();
|
||||
if (listener != null) await listener!.cancel();
|
||||
_shipments = [];
|
||||
}
|
||||
|
||||
Future<void> loadMore({bool isCustomer}) async {
|
||||
Future<void> loadMore({bool? isCustomer}) async {
|
||||
if (menuSelectedIndex == 1)
|
||||
return; // when delivered menu is not selected return
|
||||
if (_delivered.ended) return;
|
||||
@@ -59,7 +59,7 @@ class ShipmentModel extends BaseModel {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> refresh({bool isCustomer}) async {
|
||||
Future<void> refresh({bool? isCustomer}) async {
|
||||
if (menuSelectedIndex == 1)
|
||||
return; // when delivered menu is not selected return
|
||||
await _delivered.refresh(onFinished: () {
|
||||
@@ -70,16 +70,16 @@ class ShipmentModel extends BaseModel {
|
||||
Paginator _getDelivered(bool isCustomer) {
|
||||
if (!isCustomer) {
|
||||
if (user == null ||
|
||||
!((user.hasPackages() ||
|
||||
user.hasReceiving() ||
|
||||
user.hasProcessing()))) throw "No privilege";
|
||||
!((user!.hasPackages() ||
|
||||
user!.hasReceiving() ||
|
||||
user!.hasProcessing()))) throw "No privilege";
|
||||
}
|
||||
var pageQuery = Firestore.instance
|
||||
var pageQuery = FirebaseFirestore.instance
|
||||
.collection("/$shipments_collection")
|
||||
.where("is_delivered", isEqualTo: true)
|
||||
.where("is_deleted", isEqualTo: false);
|
||||
if (isCustomer) {
|
||||
pageQuery = pageQuery.where("user_id", isEqualTo: user.id);
|
||||
pageQuery = pageQuery.where("user_id", isEqualTo: user!.id);
|
||||
}
|
||||
pageQuery = pageQuery.orderBy("status_date", descending: true);
|
||||
var paginator = new Paginator(pageQuery, rowPerLoad: 20, toObj: (data, id) {
|
||||
@@ -90,30 +90,31 @@ class ShipmentModel extends BaseModel {
|
||||
|
||||
Future<void> _loadShipments(bool forCustomer, bool myPickup) async {
|
||||
if (user == null) return;
|
||||
if (!forCustomer && !user.hasShipment()) return;
|
||||
if (listener != null) listener.cancel();
|
||||
if (!forCustomer && !user!.hasShipment()) return;
|
||||
if (listener != null) listener!.cancel();
|
||||
_shipments = [];
|
||||
|
||||
try {
|
||||
var q = Firestore.instance
|
||||
var q = FirebaseFirestore.instance
|
||||
.collection("$shipments_collection")
|
||||
.where("is_delivered", isEqualTo: false)
|
||||
.where("is_canceled", isEqualTo: false)
|
||||
.where("is_deleted", isEqualTo: false);
|
||||
|
||||
if (forCustomer) {
|
||||
q = q.where("user_id", isEqualTo: user.id);
|
||||
q = q.where("user_id", isEqualTo: user!.id);
|
||||
}
|
||||
if (myPickup) {
|
||||
q = q.where("pickup_user_id", isEqualTo: user.id);
|
||||
q = q.where("pickup_user_id", isEqualTo: user!.id);
|
||||
}
|
||||
q = q.orderBy("created_at", descending: true);
|
||||
|
||||
listener = q.snapshots().listen((QuerySnapshot snapshot) {
|
||||
_shipments.clear();
|
||||
_shipments = snapshot.documents.map((documentSnapshot) {
|
||||
_shipments = snapshot.docs.map((documentSnapshot) {
|
||||
var s = Shipment.fromMap(
|
||||
documentSnapshot.data, documentSnapshot.documentID);
|
||||
documentSnapshot.data as Map<String, dynamic>,
|
||||
documentSnapshot.id);
|
||||
return s;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
@@ -130,18 +131,17 @@ class ShipmentModel extends BaseModel {
|
||||
shipment_courier_dropoff
|
||||
];
|
||||
|
||||
Shipment getActiveShipment(String shipmentID) {
|
||||
return _shipments?.firstWhere((e) => e.id == shipmentID,
|
||||
orElse: () => null);
|
||||
Shipment? getActiveShipment(String shipmentID) {
|
||||
return _shipments.firstWhere((e) => e.id == shipmentID);
|
||||
}
|
||||
|
||||
Future<Shipment> getShipment(String shipmentID) async {
|
||||
Future<Shipment?> getShipment(String shipmentID) async {
|
||||
String path = "/$shipments_collection";
|
||||
try {
|
||||
var ref = Firestore.instance.collection("$path").document(shipmentID);
|
||||
var snap = await ref.get(source: Source.server);
|
||||
var ref = FirebaseFirestore.instance.collection("$path").doc(shipmentID);
|
||||
var snap = await ref.get(const GetOptions(source: Source.server));
|
||||
if (snap.exists) {
|
||||
var s = Shipment.fromMap(snap.data, snap.documentID);
|
||||
var s = Shipment.fromMap(snap.data as Map<String, dynamic>, snap.id);
|
||||
return s;
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -150,20 +150,20 @@ class ShipmentModel extends BaseModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<List<Shipment>> getShipmentWithHandlingFee(
|
||||
Future<List<Shipment?>?> getShipmentWithHandlingFee(
|
||||
String fcsShipmentID, String userID) async {
|
||||
String path = "/$shipments_collection";
|
||||
try {
|
||||
var q = Firestore.instance
|
||||
var q = FirebaseFirestore.instance
|
||||
.collection("$path")
|
||||
.where("user_id", isEqualTo: userID)
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.where("handling_fee", isGreaterThan: 0)
|
||||
.where("fcs_shipment_id", isEqualTo: fcsShipmentID);
|
||||
var snaps = await q.getDocuments(source: Source.server);
|
||||
List<Shipment> shipments = snaps.documents.map((snap) {
|
||||
var snaps = await q.get(const GetOptions(source: Source.server));
|
||||
List<Shipment?> shipments = snaps.docs.map((snap) {
|
||||
if (snap.exists) {
|
||||
var s = Shipment.fromMap(snap.data, snap.documentID);
|
||||
var s = Shipment.fromMap(snap.data as Map<String, dynamic>, snap.id);
|
||||
return s;
|
||||
}
|
||||
}).toList();
|
||||
|
||||
@@ -14,14 +14,14 @@ 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_icons_null_safety/flutter_icons_null_safety.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'widgets.dart';
|
||||
|
||||
class ShipmentAssign extends StatefulWidget {
|
||||
final Shipment shipment;
|
||||
final Shipment? shipment;
|
||||
ShipmentAssign({this.shipment});
|
||||
|
||||
@override
|
||||
@@ -38,13 +38,13 @@ class _ShipmentAssignState extends State<ShipmentAssign> {
|
||||
TextEditingController _pickupDate = new TextEditingController();
|
||||
TextEditingController _handlingFee = new TextEditingController();
|
||||
|
||||
Shipment _shipment;
|
||||
Shipment? _shipment;
|
||||
bool _isLoading = false;
|
||||
var now = new DateTime.now();
|
||||
|
||||
String _selectedShipmentType;
|
||||
User _user;
|
||||
List<User> _users;
|
||||
String? _selectedShipmentType;
|
||||
User? _user;
|
||||
List<User>? _users;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -53,18 +53,19 @@ class _ShipmentAssignState extends State<ShipmentAssign> {
|
||||
_shipment = widget.shipment;
|
||||
_loadUsers();
|
||||
|
||||
_selectedShipmentType = _shipment.shipmentType;
|
||||
_fromTimeEditingController.text = _shipment.pickupTimeStart;
|
||||
_toTimeEditingController.text = _shipment.pickupTimeEnd;
|
||||
_pickupDate.text = dateFormatter.format(_shipment.pickupDate ?? now);
|
||||
_handlingFee.text = _shipment.handlingFee?.toString() ?? "0";
|
||||
_selectedShipmentType = _shipment!.shipmentType;
|
||||
_fromTimeEditingController.text = _shipment!.pickupTimeStart!;
|
||||
_toTimeEditingController.text = _shipment!.pickupTimeEnd!;
|
||||
_pickupDate.text = dateFormatter.format(_shipment!.pickupDate! ?? now);
|
||||
_handlingFee.text = _shipment!.handlingFee != null
|
||||
? _shipment!.handlingFee.toString()
|
||||
: "0";
|
||||
}
|
||||
|
||||
_loadUsers() async {
|
||||
StaffModel staffModel = Provider.of<StaffModel>(context, listen: false);
|
||||
var users = await staffModel.getPickupEmployees();
|
||||
var selectUser = users.firstWhere((e) => e.id == _shipment.pickupUserID,
|
||||
orElse: () => null);
|
||||
var selectUser = users.firstWhere((e) => e.id == _shipment!.pickupUserID);
|
||||
setState(() {
|
||||
_users = users;
|
||||
_user = selectUser;
|
||||
@@ -74,7 +75,7 @@ class _ShipmentAssignState extends State<ShipmentAssign> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ShipmentModel pickupModel = Provider.of<ShipmentModel>(context);
|
||||
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment);
|
||||
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment!);
|
||||
bool isLocalPickup = _selectedShipmentType == shipment_local_pickup;
|
||||
bool isCourierPickup = _selectedShipmentType == shipment_courier_pickup;
|
||||
bool isLocalDropoff = _selectedShipmentType == shipment_local_dropoff;
|
||||
@@ -146,15 +147,15 @@ class _ShipmentAssignState extends State<ShipmentAssign> {
|
||||
}
|
||||
|
||||
_save() async {
|
||||
_shipment.pickupUserID = this._user.id;
|
||||
_shipment.handlingFee = double.tryParse(_handlingFee.text) ?? 0;
|
||||
_shipment!.pickupUserID = this._user!.id;
|
||||
_shipment!.handlingFee = double.tryParse(_handlingFee.text) ?? 0;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
await shipmentModel.assignShipment(_shipment);
|
||||
await shipmentModel.assignShipment(_shipment!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,15 @@ import 'package:fcs/pages/widgets/local_text.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:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'widgets.dart';
|
||||
|
||||
class ShipmentConfirm extends StatefulWidget {
|
||||
final Shipment shipment;
|
||||
final Shipment? shipment;
|
||||
ShipmentConfirm({this.shipment});
|
||||
|
||||
@override
|
||||
@@ -27,7 +28,7 @@ class _ShipmentConfirmState extends State<ShipmentConfirm> {
|
||||
var timeFormatter = new DateFormat('jm');
|
||||
TextEditingController _handlingFee = new TextEditingController();
|
||||
|
||||
Shipment _shipment;
|
||||
Shipment? _shipment;
|
||||
bool _isLoading = false;
|
||||
var now = new DateTime.now();
|
||||
|
||||
@@ -36,17 +37,17 @@ class _ShipmentConfirmState extends State<ShipmentConfirm> {
|
||||
super.initState();
|
||||
|
||||
_shipment = widget.shipment;
|
||||
_handlingFee.text = _shipment.handlingFee?.toString() ?? "0";
|
||||
_handlingFee.text = _shipment!.handlingFee?.toString() ?? "0";
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment);
|
||||
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment!);
|
||||
|
||||
final handlingFeeBox = InputText(
|
||||
labelTextKey: "shipment.handling.fee",
|
||||
controller: _handlingFee,
|
||||
iconData: FontAwesome.truck,
|
||||
iconData: FontAwesomeIcons.truck,
|
||||
);
|
||||
final confirmbtn = LocalButton(
|
||||
textKey: "shipment.confirm.btn",
|
||||
@@ -94,14 +95,14 @@ class _ShipmentConfirmState extends State<ShipmentConfirm> {
|
||||
}
|
||||
|
||||
_save() async {
|
||||
_shipment.handlingFee = double.tryParse(_handlingFee.text) ?? 0;
|
||||
_shipment!.handlingFee = double.tryParse(_handlingFee.text) ?? 0;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
await shipmentModel.confirmShipment(_shipment);
|
||||
await shipmentModel.confirmShipment(_shipment!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
|
||||
@@ -29,7 +29,7 @@ import 'shipment_box_editor.dart';
|
||||
import 'widgets.dart';
|
||||
|
||||
class ShipmentEditor extends StatefulWidget {
|
||||
final Shipment shipment;
|
||||
final Shipment? shipment;
|
||||
ShipmentEditor({this.shipment});
|
||||
|
||||
@override
|
||||
@@ -45,12 +45,12 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
TextEditingController _toTimeEditingController = new TextEditingController();
|
||||
TextEditingController _pickupDate = new TextEditingController();
|
||||
|
||||
Shipment _shipment;
|
||||
Shipment? _shipment;
|
||||
bool _isLoading = false;
|
||||
var now = new DateTime.now();
|
||||
bool _isNew;
|
||||
late bool _isNew;
|
||||
|
||||
String _selectedShipmentType;
|
||||
String? _selectedShipmentType;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -59,20 +59,21 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
if (widget.shipment != null) {
|
||||
_isNew = false;
|
||||
_shipment = widget.shipment;
|
||||
_selectedShipmentType = _shipment.shipmentType;
|
||||
_fromTimeEditingController.text = _shipment.pickupTimeStart;
|
||||
_toTimeEditingController.text = _shipment.pickupTimeEnd;
|
||||
_pickupDate.text = dateFormatter.format(_shipment.pickupDate ?? now);
|
||||
_selectedShipmentType = _shipment!.shipmentType;
|
||||
_fromTimeEditingController.text = _shipment!.pickupTimeStart ?? "";
|
||||
_toTimeEditingController.text = _shipment!.pickupTimeEnd ?? "";
|
||||
_pickupDate.text = dateFormatter.format(_shipment!.pickupDate ?? now);
|
||||
} else {
|
||||
_isNew = true;
|
||||
_selectedShipmentType = shipment_local_pickup;
|
||||
_pickupDate.text = dateFormatter.format(now);
|
||||
_fromTimeEditingController.text = "${timeFormatter.format(now)}";
|
||||
_toTimeEditingController.text = "${timeFormatter.format(now)}";
|
||||
_shipment = Shipment(boxes: []);
|
||||
// _shipment = Shipment(boxes: []);
|
||||
var shipmentModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
_shipment.pickupAddress = shipmentModel.defalutAddress;
|
||||
_shipment!.pickupAddress = shipmentModel.defalutAddress;
|
||||
_shipment!.boxes = [];
|
||||
_pickupDate.text = dateFormatter.format(now);
|
||||
}
|
||||
}
|
||||
@@ -86,7 +87,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
Widget build(BuildContext context) {
|
||||
MainModel mainModel = Provider.of<MainModel>(context);
|
||||
ShipmentModel pickupModel = Provider.of<ShipmentModel>(context);
|
||||
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment);
|
||||
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment!);
|
||||
bool isLocalPickup = _selectedShipmentType == shipment_local_pickup;
|
||||
bool isCourierPickup = _selectedShipmentType == shipment_courier_pickup;
|
||||
bool isLocalDropoff = _selectedShipmentType == shipment_local_dropoff;
|
||||
@@ -121,20 +122,20 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
backgroundColor: Colors.white,
|
||||
));
|
||||
final pickupAddressBox = DefaultDeliveryAddress(
|
||||
deliveryAddress: _shipment.pickupAddress,
|
||||
deliveryAddress: _shipment!.pickupAddress,
|
||||
iconData: Icons.location_on,
|
||||
labelKey: "shipment.location",
|
||||
onTap: () async {
|
||||
DeliveryAddress address = await Navigator.push<DeliveryAddress>(
|
||||
DeliveryAddress? address = await Navigator.push<DeliveryAddress>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _shipment.pickupAddress,
|
||||
deliveryAddress: _shipment!.pickupAddress,
|
||||
user: mainModel.user)),
|
||||
);
|
||||
if (address == null) return;
|
||||
setState(() {
|
||||
_shipment.pickupAddress = address;
|
||||
_shipment!.pickupAddress = address;
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -142,7 +143,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
FcsIDIcon(),
|
||||
Expanded(
|
||||
child: DisplayText(
|
||||
text: mainModel.setting.usaAddress,
|
||||
text: mainModel.setting!.usaAddress,
|
||||
),
|
||||
)
|
||||
]);
|
||||
@@ -194,7 +195,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
LocalRadioButtons(
|
||||
values: pickupModel.shipmentTypes,
|
||||
selectedValue: _selectedShipmentType,
|
||||
callback: (v) {
|
||||
callback: (String? v) {
|
||||
setState(() {
|
||||
_selectedShipmentType = v;
|
||||
});
|
||||
@@ -239,7 +240,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
),
|
||||
),
|
||||
Column(
|
||||
children: getBoxList(context, _shipment.boxes),
|
||||
children: getBoxList(context, _shipment!.boxes),
|
||||
),
|
||||
_isNew ? createBtn : updateBtn,
|
||||
],
|
||||
@@ -276,7 +277,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
_addBox(Carton box) {
|
||||
if (box == null) return;
|
||||
box.cartonType = carton_from_shipments;
|
||||
_shipment.boxes.add(box);
|
||||
_shipment!.boxes.add(box);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@@ -287,15 +288,15 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
|
||||
_removeBox(Carton box) {
|
||||
if (box == null) return;
|
||||
_shipment.boxes.remove(box);
|
||||
_shipment!.boxes.remove(box);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
_save() async {
|
||||
_shipment.shipmentType = this._selectedShipmentType;
|
||||
_shipment.pickupDate = dateFormatter.parse(_pickupDate.text);
|
||||
_shipment.pickupTimeStart = _fromTimeEditingController.text;
|
||||
_shipment.pickupTimeEnd = _toTimeEditingController.text;
|
||||
_shipment!.shipmentType = this._selectedShipmentType;
|
||||
_shipment!.pickupDate = dateFormatter.parse(_pickupDate.text);
|
||||
_shipment!.pickupTimeStart = _fromTimeEditingController.text;
|
||||
_shipment!.pickupTimeEnd = _toTimeEditingController.text;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
@@ -303,9 +304,9 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
if (_isNew) {
|
||||
await shipmentModel.createShipment(_shipment);
|
||||
await shipmentModel.createShipment(_shipment!);
|
||||
} else {
|
||||
await shipmentModel.updateShipment(_shipment);
|
||||
await shipmentModel.updateShipment(_shipment!);
|
||||
}
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
@@ -319,10 +320,10 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
|
||||
_openCourierWebsite() {
|
||||
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
|
||||
launch("${mainModel.setting.courierWebsite}");
|
||||
launch("${mainModel.setting!.courierWebsite}");
|
||||
}
|
||||
|
||||
isDataChanged() {
|
||||
return _shipment.boxes.isNotEmpty;
|
||||
return _shipment!.boxes.isNotEmpty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -17,7 +17,7 @@ import 'shipment_list_row.dart';
|
||||
class ShipmentList extends StatefulWidget {
|
||||
final bool forCustomer;
|
||||
|
||||
const ShipmentList({Key key, this.forCustomer = true}) : super(key: key);
|
||||
const ShipmentList({Key? key, this.forCustomer = true}) : super(key: key);
|
||||
@override
|
||||
_ShipmentListState createState() => _ShipmentListState();
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@ import 'package:fcs/domain/entities/shipment.dart';
|
||||
import 'package:fcs/helpers/theme.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 '../main/util.dart';
|
||||
import 'shipment_info.dart';
|
||||
|
||||
class ShipmentListRow extends StatelessWidget {
|
||||
final Shipment shipment;
|
||||
final bool isCustomer;
|
||||
const ShipmentListRow({Key key, this.shipment, this.isCustomer})
|
||||
final Shipment? shipment;
|
||||
final bool? isCustomer;
|
||||
const ShipmentListRow({Key? key, this.shipment, this.isCustomer})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
@@ -45,7 +45,7 @@ class ShipmentListRow extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
shipment.shipmentNumber ?? "",
|
||||
shipment!.shipmentNumber ?? "",
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.black),
|
||||
),
|
||||
@@ -69,7 +69,7 @@ class ShipmentListRow extends StatelessWidget {
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(0),
|
||||
child: getStatus(shipment.status ?? ""),
|
||||
child: getStatus(shipment!.status ?? ""),
|
||||
),
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.only(left: 8.0, top: 5, bottom: 5),
|
||||
|
||||
@@ -11,14 +11,14 @@ 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_icons_null_safety/flutter_icons_null_safety.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'widgets.dart';
|
||||
|
||||
class ShipmentPack extends StatefulWidget {
|
||||
final Shipment shipment;
|
||||
final Shipment? shipment;
|
||||
ShipmentPack({this.shipment});
|
||||
|
||||
@override
|
||||
@@ -29,12 +29,12 @@ class _ShipmentPackState extends State<ShipmentPack> {
|
||||
var dateFormatter = new DateFormat('dd MMM yyyy');
|
||||
var timeFormatter = new DateFormat('jm');
|
||||
|
||||
Shipment _shipment;
|
||||
Shipment? _shipment;
|
||||
bool _isLoading = false;
|
||||
var now = new DateTime.now();
|
||||
|
||||
FcsShipment _fcsShipment;
|
||||
List<FcsShipment> _fcsShipments;
|
||||
FcsShipment? _fcsShipment;
|
||||
List<FcsShipment>? _fcsShipments;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -48,8 +48,8 @@ class _ShipmentPackState extends State<ShipmentPack> {
|
||||
FcsShipmentModel fcsShipmentModel =
|
||||
Provider.of<FcsShipmentModel>(context, listen: false);
|
||||
var fcsShipments = await fcsShipmentModel.getActiveFcsShipments();
|
||||
var fcsShipment = fcsShipments
|
||||
.firstWhere((e) => e.id == _shipment.fcsShipmentID, orElse: () => null);
|
||||
var fcsShipment =
|
||||
fcsShipments.firstWhere((e) => e.id == _shipment?.fcsShipmentID);
|
||||
setState(() {
|
||||
_fcsShipments = fcsShipments;
|
||||
_fcsShipment = fcsShipment;
|
||||
@@ -58,7 +58,7 @@ class _ShipmentPackState extends State<ShipmentPack> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment);
|
||||
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment!);
|
||||
|
||||
var fcsShipmentsBox = LocalDropdown<FcsShipment>(
|
||||
callback: (v) {
|
||||
@@ -120,14 +120,14 @@ class _ShipmentPackState extends State<ShipmentPack> {
|
||||
}
|
||||
|
||||
_save() async {
|
||||
_shipment.fcsShipmentID = this._fcsShipment.id;
|
||||
_shipment!.fcsShipmentID = this._fcsShipment!.id;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
await shipmentModel.packShipment(_shipment);
|
||||
await shipmentModel.packShipment(_shipment!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
|
||||
Reference in New Issue
Block a user