null safety

This commit is contained in:
phyothandar
2021-09-10 15:22:11 +06:30
parent 51a5fe0740
commit c90661b262
24 changed files with 194 additions and 193 deletions

View File

@@ -15,14 +15,14 @@ import 'package:path/path.dart' as Path;
class InvoiceModel extends BaseModel {
final log = Logger('InvoiceModel');
StreamSubscription<QuerySnapshot> listener;
StreamSubscription<QuerySnapshot<Map<String, dynamic>>>? listener;
List<Invoice> _invoices = [];
List<Invoice> get invoices =>
_selectedIndex == 1 ? _invoices : List<Invoice>.from(_paginator.values);
Paginator _paginator;
late Paginator _paginator;
bool endOfPaidInvoices = false;
bool isLoading = false;
@@ -33,7 +33,7 @@ class InvoiceModel extends BaseModel {
notifyListeners();
}
get selectedIndex => _selectedIndex;
int get selectedIndex => _selectedIndex;
@override
void privilegeChanged() {
@@ -54,11 +54,11 @@ class InvoiceModel extends BaseModel {
if (user == null) return;
if (!forCustomer && !user.hasInvoices()) return;
String path = "/$invoices_collection";
if (listener != null) listener.cancel();
if (listener != null) listener!.cancel();
_invoices = [];
try {
var q = Firestore.instance
var q = FirebaseFirestore.instance
.collection("$path")
.where("status", isEqualTo: invoice_issued_status)
.where("is_deleted", isEqualTo: false);
@@ -69,9 +69,9 @@ class InvoiceModel extends BaseModel {
listener = q.snapshots().listen((QuerySnapshot snapshot) {
_invoices.clear();
_invoices = snapshot.documents.map((documentSnapshot) {
var s = Invoice.fromMap(
documentSnapshot.data, documentSnapshot.documentID);
_invoices = snapshot.docs.map((documentSnapshot) {
var s = Invoice.fromMap(documentSnapshot.data as Map<String, dynamic>,
documentSnapshot.id);
return s;
}).toList();
notifyListeners();
@@ -85,7 +85,7 @@ class InvoiceModel extends BaseModel {
if (!isCustomer) {
if (user == null || !(user.hasInvoices())) throw "No privilege";
}
var pageQuery = Firestore.instance
var pageQuery = FirebaseFirestore.instance
.collection("/$invoices_collection")
.where("is_deleted", isEqualTo: false);
if (isCustomer) {
@@ -105,7 +105,7 @@ class InvoiceModel extends BaseModel {
return paginator;
}
Future<void> loadMore({bool isCustomer}) async {
Future<void> loadMore({bool? isCustomer}) async {
if (_paginator.ended || _selectedIndex == 1)
return; // when paid menu is not selected return
isLoading = true;
@@ -116,7 +116,7 @@ class InvoiceModel extends BaseModel {
});
}
Future<void> refresh({bool isCustomer}) async {
Future<void> refresh({bool? isCustomer}) async {
if (_selectedIndex == 1) return; // when paid menu is not selected return
await _paginator.refresh(onFinished: () {
notifyListeners();
@@ -129,17 +129,17 @@ class InvoiceModel extends BaseModel {
logout() async {
if (_paginator != null) _paginator.close();
if (listener != null) await listener.cancel();
if (listener != null) await listener!.cancel();
_invoices = [];
}
Future<Invoice> getInvoice(String id) async {
Future<Invoice?> getInvoice(String id) async {
String path = "/$invoices_collection";
try {
var ref = Firestore.instance.collection("$path").document(id);
var snap = await ref.get(source: Source.server);
var ref = FirebaseFirestore.instance.collection("$path").doc(id);
var snap = await ref.get(const GetOptions(source: Source.server));
if (snap.exists) {
var s = Invoice.fromMap(snap.data, snap.documentID);
var s = Invoice.fromMap(snap.data as Map<String, dynamic>, snap.id);
return s;
}
} catch (e) {