check null safety

This commit is contained in:
tzw
2021-09-10 16:33:52 +06:30
parent 3eacbef117
commit d8c86a512b
46 changed files with 275 additions and 304 deletions

View File

@@ -40,7 +40,7 @@ class _CustomerEditorState extends State<CustomerEditor> {
)),
IconButton(
icon: Icon(Icons.open_in_new, color: primaryColor),
onPressed: () => call(context, widget.customer!.phoneNumber)),
onPressed: () => call(context, widget.customer?.phoneNumber ?? "")),
],
);
@@ -68,7 +68,7 @@ class _CustomerEditorState extends State<CustomerEditor> {
onPressed: () => Navigator.of(context).pop(),
),
title: Text(
widget.customer!.name,
widget.customer?.name ?? "",
style: TextStyle(
fontSize: 20,
color: primaryColor,
@@ -119,7 +119,7 @@ class _CustomerEditorState extends State<CustomerEditor> {
CustomerModel customerModel =
Provider.of<CustomerModel>(context, listen: false);
try {
await customerModel.acceptRequest(widget.customer!.id);
await customerModel.acceptRequest(widget.customer?.id ?? "");
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -125,7 +125,7 @@ class _CustomerListState extends State<CustomerList> {
Padding(
padding: const EdgeInsets.only(top: 2.0),
child: new Text(
customer.name,
customer.name ?? "",
style: new TextStyle(
fontSize: 20.0, color: primaryColor),
),
@@ -171,7 +171,7 @@ class _CustomerListState extends State<CustomerList> {
children: [
Padding(
padding: const EdgeInsets.only(right: 5),
child: _status(customer.status),
child: _status(customer.status ?? ""),
),
Padding(
padding: const EdgeInsets.only(right: 5),
@@ -222,17 +222,17 @@ class _CustomerListState extends State<CustomerList> {
)))
.then((value) {
if (customer.fcsUnseenCount > 0) {
messageModel.seenMessages(customer.id, false);
messageModel.seenMessages(customer.id ?? "", false);
}
});
if (customer.fcsUnseenCount > 0) {
messageModel.seenMessages(customer.id, false);
messageModel.seenMessages(customer.id ?? "", false);
}
}
_share(User user) async {
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
String appUrl = mainModel.setting.appUrl;
String appUrl = mainModel.setting?.appUrl ?? "";
final RenderBox? box = context.findRenderObject() as RenderBox;
await Share.share(
"Join us on FCS Logistics App. Here is the link:\n $appUrl\n" +

View File

@@ -37,7 +37,7 @@ class _InvitationEditorState extends State<InvitationEditor> {
)),
IconButton(
icon: Icon(Icons.open_in_new, color: primaryColor),
onPressed: () => call(context, widget.customer!.phoneNumber)),
onPressed: () => call(context, widget.customer?.phoneNumber ?? "")),
],
);
@@ -57,7 +57,7 @@ class _InvitationEditorState extends State<InvitationEditor> {
onPressed: () => Navigator.of(context).pop(),
),
title: Text(
widget.customer!.name,
widget.customer?.name ?? "",
style: TextStyle(fontSize: 20, color: primaryColor),
),
),
@@ -87,7 +87,7 @@ class _InvitationEditorState extends State<InvitationEditor> {
CustomerModel customerModel =
Provider.of<CustomerModel>(context, listen: false);
try {
await customerModel.deleteInvite(widget.customer!.phoneNumber);
await customerModel.deleteInvite(widget.customer?.phoneNumber ?? "");
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -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);
}
}