fix errors

This commit is contained in:
Sai Naw Wun
2020-10-22 04:14:53 +06:30
parent 2021f74872
commit e5540c5491
32 changed files with 1069 additions and 811 deletions

View File

@@ -2,7 +2,9 @@ import 'dart:async';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:fcs/data/services/services.dart';
import 'package:fcs/domain/constants.dart';
import 'package:fcs/domain/entities/discount.dart';
import 'package:fcs/helpers/paginator.dart';
import 'package:fcs/pages/main/model/base_model.dart';
import 'package:logging/logging.dart';
@@ -11,7 +13,28 @@ class DiscountModel extends BaseModel {
StreamSubscription<QuerySnapshot> listener;
List<Discount> discounts = [];
List<Discount> _discounts = [];
List<Discount> get discounts =>
_selectedIndex == 1 ? _discounts : List<Discount>.from(_used.values);
Paginator _used;
bool isLoading = false;
int _selectedIndex = 1;
set selectedIndex(int index) {
_selectedIndex = index;
notifyListeners();
}
get selectedIndex => _selectedIndex;
initData() {
_selectedIndex = 1;
_load();
if (_used != null) _used.close();
_used = _getUsed();
_used.load();
}
void initUser(user) {
super.initUser(user);
@@ -22,7 +45,7 @@ class DiscountModel extends BaseModel {
if (listener != null) listener.cancel();
try {
listener = Firestore.instance
.collection("/discounts")
.collection("/$discounts_collection")
.orderBy("code", descending: false)
.snapshots()
.listen((snaps) {
@@ -37,9 +60,42 @@ class DiscountModel extends BaseModel {
}
}
Paginator _getUsed() {
if (user == null || !user.hasFcsShipments()) return null;
var pageQuery = Firestore.instance
.collection("/$discounts_collection")
.where("status", isEqualTo: fcs_shipment_shipped_status)
.orderBy("code", descending: false);
var paginator = new Paginator(pageQuery, rowPerLoad: 20, toObj: (data, id) {
return Discount.fromMap(data, id);
});
return paginator;
}
Future<void> loadMore() async {
if (_used.ended || _selectedIndex == 1) return;
isLoading = true;
notifyListeners();
await _used.load(onFinished: () {
isLoading = false;
notifyListeners();
});
}
Future<void> refresh() async {
if (_selectedIndex == 1) return;
await _used.refresh(onFinished: () {
notifyListeners();
});
}
@override
logout() async {
discounts = [];
if (listener != null) await listener.cancel();
if (_used != null) _used.close();
_discounts = [];
}
Future<void> addDiscount(Discount discount) async {