null safety

This commit is contained in:
phyothandar
2021-09-10 16:48:21 +06:30
parent 03c5fc5016
commit bb4f4ad7c2
40 changed files with 393 additions and 352 deletions

View File

@@ -12,21 +12,22 @@ class PaymentMethodModel extends BaseModel {
List<PaymentMethod> paymentMethods = [];
PaymentMethod getPaymentMethod(String id) {
return paymentMethods.firstWhere((e) => e.id == id, orElse: () => null);
return paymentMethods.firstWhere((e) => e.id == id);
}
StreamSubscription<QuerySnapshot> listener;
StreamSubscription<QuerySnapshot>? listener;
PaymentMethodModel() {
if (listener != null) listener.cancel();
if (listener != null) listener!.cancel();
try {
listener = Firestore.instance
listener = FirebaseFirestore.instance
.collection("/payment_methods")
.snapshots()
.listen((snaps) {
paymentMethods.clear();
snaps.documents.forEach((d) {
paymentMethods.add(PaymentMethod.fromMap(d.data, d.documentID));
snaps.docs.forEach((d) {
paymentMethods
.add(PaymentMethod.fromMap(d.data as Map<String, dynamic>, d.id));
});
notifyListeners();
});