check null safety
This commit is contained in:
@@ -12,8 +12,8 @@ class CustomerModel extends BaseModel {
|
||||
|
||||
List<User> customers = [];
|
||||
List<User> invitations = [];
|
||||
late StreamSubscription<QuerySnapshot?> customerListener;
|
||||
late StreamSubscription<QuerySnapshot?> invitationListener;
|
||||
late StreamSubscription<QuerySnapshot>? customerListener;
|
||||
late StreamSubscription<QuerySnapshot>? invitationListener;
|
||||
|
||||
@override
|
||||
void privilegeChanged() {
|
||||
@@ -24,8 +24,8 @@ class CustomerModel extends BaseModel {
|
||||
|
||||
@override
|
||||
logout() async {
|
||||
if (customerListener != null) customerListener.cancel();
|
||||
if (invitationListener != null) invitationListener.cancel();
|
||||
if (customerListener != null) customerListener!.cancel();
|
||||
if (invitationListener != null) invitationListener!.cancel();
|
||||
customers = [];
|
||||
invitations = [];
|
||||
}
|
||||
@@ -43,21 +43,22 @@ class CustomerModel extends BaseModel {
|
||||
}
|
||||
|
||||
Future<void> _loadCustomer() async {
|
||||
if (user == null || !user.hasCustomers()) return;
|
||||
if (user == null && !user!.hasCustomers()) return;
|
||||
|
||||
try {
|
||||
if (customerListener != null) customerListener.cancel();
|
||||
if (customerListener != null) customerListener!.cancel();
|
||||
|
||||
customerListener = Firestore.instance
|
||||
customerListener = FirebaseFirestore.instance
|
||||
.collection("/$user_collection")
|
||||
.where("is_sys_admin", isEqualTo: false)
|
||||
.orderBy("message_time", descending: true)
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
customers.clear();
|
||||
customers = snapshot.documents.map((documentSnapshot) {
|
||||
var user =
|
||||
User.fromMap(documentSnapshot.data, documentSnapshot.documentID);
|
||||
customers = snapshot.docs.map((documentSnapshot) {
|
||||
var user = User.fromMap(
|
||||
documentSnapshot.data() as Map<String, dynamic>,
|
||||
documentSnapshot.id);
|
||||
return user;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
@@ -68,19 +69,20 @@ class CustomerModel extends BaseModel {
|
||||
}
|
||||
|
||||
Future<void> _loadInvitations() async {
|
||||
if (user == null || !user.hasCustomers()) return;
|
||||
if (user == null && !user!.hasCustomers()) return;
|
||||
|
||||
try {
|
||||
if (invitationListener != null) invitationListener.cancel();
|
||||
if (invitationListener != null) invitationListener!.cancel();
|
||||
|
||||
invitationListener = Firestore.instance
|
||||
invitationListener = FirebaseFirestore.instance
|
||||
.collection("/$invitations_collection")
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
invitations.clear();
|
||||
invitations = snapshot.documents.map((documentSnapshot) {
|
||||
var user =
|
||||
User.fromMap(documentSnapshot.data, documentSnapshot.documentID);
|
||||
invitations = snapshot.docs.map((documentSnapshot) {
|
||||
var user = User.fromMap(
|
||||
documentSnapshot.data() as Map<String, dynamic>,
|
||||
documentSnapshot.id);
|
||||
return user;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
@@ -92,21 +94,20 @@ class CustomerModel extends BaseModel {
|
||||
|
||||
Future<User> getUser(String? id) async {
|
||||
String path = "/$user_collection";
|
||||
var snap = await Firestore.instance.collection(path).document(id).get();
|
||||
return User.fromMap(snap.data, snap.documentID);
|
||||
var snap = await FirebaseFirestore.instance.collection(path).doc(id).get();
|
||||
return User.fromMap(snap.data() as Map<String, dynamic>, snap.id);
|
||||
}
|
||||
|
||||
Future<List<User>> getInvoiceUsers(String fcsShipmentID) async {
|
||||
List<User> users = [];
|
||||
try {
|
||||
var snaps = await Firestore.instance
|
||||
var snaps = await FirebaseFirestore.instance
|
||||
.collection(
|
||||
"/$fcs_shipment_collection/$fcsShipmentID/$user_collection")
|
||||
.where("pending_invoice_carton_count", isGreaterThan: 0)
|
||||
.getDocuments(source: Source.server);
|
||||
users = snaps.documents.map((documentSnapshot) {
|
||||
var user =
|
||||
User.fromMap(documentSnapshot.data, documentSnapshot.documentID);
|
||||
.get(GetOptions(source: Source.server));
|
||||
users = snaps.docs.map((documentSnapshot) {
|
||||
var user = User.fromMap(documentSnapshot.data(), documentSnapshot.id);
|
||||
return user;
|
||||
}).toList();
|
||||
} catch (e) {
|
||||
@@ -116,6 +117,6 @@ class CustomerModel extends BaseModel {
|
||||
}
|
||||
|
||||
Future<void> enableUser(User user, bool enabled) {
|
||||
return Services.instance.userService.enableUser(user.id, enabled);
|
||||
return Services.instance.userService.enableUser(user.id ?? "", enabled);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user