check null safety
This commit is contained in:
@@ -12,7 +12,7 @@ import 'package:logging/logging.dart';
|
||||
|
||||
class CartonModel extends BaseModel {
|
||||
List<Carton> _boxes = [];
|
||||
PaginatorListener? cartonsByFilter;
|
||||
late PaginatorListener<Carton> cartonsByFilter;
|
||||
|
||||
final log = Logger('CartonModel');
|
||||
List<Carton> get boxes => _selectedIndex == 1
|
||||
@@ -24,8 +24,8 @@ class CartonModel extends BaseModel {
|
||||
int _selectedIndexFilter = 1;
|
||||
bool isLoading = false;
|
||||
|
||||
StreamSubscription<QuerySnapshot> listener;
|
||||
StreamSubscription<QuerySnapshot> cartonListener;
|
||||
StreamSubscription<QuerySnapshot>? listener;
|
||||
StreamSubscription<QuerySnapshot>? cartonListener;
|
||||
static List<ShipmentStatus> statusHistory = [
|
||||
ShipmentStatus(status: "Packed", date: DateTime(2020, 6, 1), done: true),
|
||||
ShipmentStatus(status: "Shipped", date: DateTime(2020, 6, 5), done: false),
|
||||
@@ -101,7 +101,7 @@ class CartonModel extends BaseModel {
|
||||
|
||||
@override
|
||||
void privilegeChanged() {
|
||||
if (user != null || !user.hasCarton()) {
|
||||
if (user != null || !user!.hasCarton()) {
|
||||
_initData();
|
||||
}
|
||||
}
|
||||
@@ -119,12 +119,12 @@ class CartonModel extends BaseModel {
|
||||
}
|
||||
|
||||
Future<void> _loadBoxes() async {
|
||||
if (user == null || !user.hasCarton()) return;
|
||||
if (user == null || !user!.hasCarton()) return;
|
||||
String path = "/$cartons_collection/";
|
||||
if (listener != null) listener.cancel();
|
||||
if (listener != null) listener!.cancel();
|
||||
_boxes = [];
|
||||
try {
|
||||
listener = Firestore.instance
|
||||
listener = FirebaseFirestore.instance
|
||||
.collection("$path")
|
||||
.where("status",
|
||||
whereIn: [carton_packed_status, carton_shipped_status])
|
||||
@@ -133,9 +133,10 @@ class CartonModel extends BaseModel {
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
_boxes.clear();
|
||||
_boxes = snapshot.documents.map((documentSnapshot) {
|
||||
_boxes = snapshot.docs.map((documentSnapshot) {
|
||||
var s = Carton.fromMap(
|
||||
documentSnapshot.data, documentSnapshot.documentID);
|
||||
documentSnapshot.data() as Map<String, dynamic>,
|
||||
documentSnapshot.id);
|
||||
return s;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
@@ -146,18 +147,18 @@ class CartonModel extends BaseModel {
|
||||
}
|
||||
|
||||
Future<void> _loadCartonsByFilter(String orderName) async {
|
||||
if (user == null || !user.hasCarton()) return null;
|
||||
if (user == null || !user!.hasCarton()) return null;
|
||||
String path = "/$cartons_collection";
|
||||
|
||||
try {
|
||||
Query listenerQuery = Firestore.instance
|
||||
Query listenerQuery = FirebaseFirestore.instance
|
||||
.collection("$path")
|
||||
.where("carton_type", whereIn: [
|
||||
carton_from_packages,
|
||||
carton_from_cartons
|
||||
]).where("status", isEqualTo: carton_packed_status);
|
||||
|
||||
Query pageQuery = Firestore.instance
|
||||
Query pageQuery = FirebaseFirestore.instance
|
||||
.collection("$path")
|
||||
.where("carton_type",
|
||||
whereIn: [carton_from_packages, carton_from_cartons])
|
||||
@@ -171,10 +172,10 @@ class CartonModel extends BaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
Paginator _getDelivered() {
|
||||
if (user == null || !user.hasCarton()) return null;
|
||||
Paginator? _getDelivered() {
|
||||
if (user == null || !user!.hasCarton()) return null;
|
||||
|
||||
var pageQuery = Firestore.instance
|
||||
var pageQuery = FirebaseFirestore.instance
|
||||
.collection("/$cartons_collection")
|
||||
.where("is_delivered", isEqualTo: true)
|
||||
.where("is_deleted", isEqualTo: false);
|
||||
@@ -185,10 +186,10 @@ class CartonModel extends BaseModel {
|
||||
}
|
||||
|
||||
Future<void> loadMore() async {
|
||||
if (_delivered.ended || selectedIndex == 1) return;
|
||||
if (_delivered == null && _delivered!.ended || selectedIndex == 1) return;
|
||||
isLoading = true;
|
||||
notifyListeners();
|
||||
await _delivered.load(onFinished: () {
|
||||
await _delivered!.load(onFinished: () {
|
||||
isLoading = false;
|
||||
notifyListeners();
|
||||
});
|
||||
@@ -196,7 +197,7 @@ class CartonModel extends BaseModel {
|
||||
|
||||
Future<void> refresh() async {
|
||||
if (selectedIndex == 1) return;
|
||||
await _delivered.refresh(onFinished: () {
|
||||
await _delivered?.refresh(onFinished: () {
|
||||
notifyListeners();
|
||||
});
|
||||
}
|
||||
@@ -207,69 +208,62 @@ class CartonModel extends BaseModel {
|
||||
|
||||
@override
|
||||
logout() async {
|
||||
if (listener != null) await listener.cancel();
|
||||
if (cartonListener != null) await cartonListener.cancel();
|
||||
if (_delivered != null) _delivered.close();
|
||||
if (listener != null) await listener!.cancel();
|
||||
if (cartonListener != null) await cartonListener!.cancel();
|
||||
if (_delivered != null) _delivered!.close();
|
||||
if (cartonsByFilter != null) cartonsByFilter.close();
|
||||
_boxes = [];
|
||||
}
|
||||
|
||||
Future<List<Carton>> getCartons(String shipmentID) async {
|
||||
String path = "/$cartons_collection";
|
||||
var querySnap = await Firestore.instance
|
||||
var querySnap = await FirebaseFirestore.instance
|
||||
.collection(path)
|
||||
.where("shipment_id", isEqualTo: shipmentID)
|
||||
.getDocuments();
|
||||
return querySnap.documents
|
||||
.map((e) => Carton.fromMap(e.data, e.documentID))
|
||||
.toList();
|
||||
.get();
|
||||
return querySnap.docs.map((e) => Carton.fromMap(e.data(), e.id)).toList();
|
||||
}
|
||||
|
||||
Future<List<Carton>> getCartonsByFcsShipment(String fcsShipmentID) async {
|
||||
String path = "/$cartons_collection";
|
||||
var querySnap = await Firestore.instance
|
||||
var querySnap = await FirebaseFirestore.instance
|
||||
.collection(path)
|
||||
.where("fcs_shipment_id", isEqualTo: fcsShipmentID)
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.getDocuments();
|
||||
return querySnap.documents
|
||||
.map((e) => Carton.fromMap(e.data, e.documentID))
|
||||
.toList();
|
||||
.get();
|
||||
return querySnap.docs.map((e) => Carton.fromMap(e.data(), e.id)).toList();
|
||||
}
|
||||
|
||||
Future<List<Carton>> getCartonsForInvoice(
|
||||
String fcsShipmentID, String userID) async {
|
||||
String path = "/$cartons_collection";
|
||||
var querySnap = await Firestore.instance
|
||||
var querySnap = await FirebaseFirestore.instance
|
||||
.collection(path)
|
||||
.where("fcs_shipment_id", isEqualTo: fcsShipmentID)
|
||||
.where("user_id", isEqualTo: userID)
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.where("is_invoiced", isEqualTo: false)
|
||||
.getDocuments();
|
||||
List<Carton> cartons = querySnap.documents
|
||||
.map((e) => Carton.fromMap(e.data, e.documentID))
|
||||
.toList();
|
||||
.get();
|
||||
List<Carton> cartons =
|
||||
querySnap.docs.map((e) => Carton.fromMap(e.data(), e.id)).toList();
|
||||
return cartons;
|
||||
}
|
||||
|
||||
Future<List<Carton>> getMixCartonsByFcsShipment(String fcsShipmentID) async {
|
||||
String path = "/$cartons_collection";
|
||||
var querySnap = await Firestore.instance
|
||||
var querySnap = await FirebaseFirestore.instance
|
||||
.collection(path)
|
||||
.where("fcs_shipment_id", isEqualTo: fcsShipmentID)
|
||||
.where("carton_type", isEqualTo: carton_mix_box)
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.getDocuments();
|
||||
return querySnap.documents
|
||||
.map((e) => Carton.fromMap(e.data, e.documentID))
|
||||
.toList();
|
||||
.get();
|
||||
return querySnap.docs.map((e) => Carton.fromMap(e.data(), e.id)).toList();
|
||||
}
|
||||
|
||||
Future<Carton> getCarton(String id) async {
|
||||
String path = "/$cartons_collection";
|
||||
var snap = await Firestore.instance.collection(path).document(id).get();
|
||||
return Carton.fromMap(snap.data, snap.documentID);
|
||||
var snap = await FirebaseFirestore.instance.collection(path).doc(id).get();
|
||||
return Carton.fromMap(snap.data() as Map<String, dynamic>, snap.id);
|
||||
}
|
||||
|
||||
Future<Carton> createCarton(Carton carton) {
|
||||
|
||||
Reference in New Issue
Block a user