import 'dart:async'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:fcs/data/services/services.dart'; import 'package:fcs/constants.dart'; import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/pages/main/model/base_model.dart'; import 'package:logging/logging.dart'; import '../../../pagination/paginator_listener.dart'; class DeliveryModel extends BaseModel { final log = Logger('DeliveryModel'); PaginatorListener? getCartons; int selectedIndex = 1; onChanged(int index) { selectedIndex = index; loadPaginationCartons(selectedIndex); notifyListeners(); } loadPaginationCartons(int index) { if (user == null || !user!.hasDeliveries()) return; String path = "/$cartons_collection"; Query col = FirebaseFirestore.instance.collection(path); Query pageQuery = FirebaseFirestore.instance.collection(path); if (index == 1) { col = col .where("status", isEqualTo: carton_shipped_status) .where("carton_type", whereIn: [ carton_from_packages, carton_from_shipments, carton_small_bag ]); pageQuery = pageQuery .where("status", isEqualTo: carton_shipped_status) .where("carton_type", whereIn: [ carton_from_packages, carton_from_shipments, carton_small_bag ]); } if (index == 2) { col = col .where("is_delivered", isEqualTo: true) .where("status", whereIn: [carton_delivered_status]); pageQuery = pageQuery .where("is_delivered", isEqualTo: true) .where("status", whereIn: [carton_delivered_status]); } pageQuery = pageQuery.orderBy("carton_number"); getCartons?.close(); getCartons = PaginatorListener( col, pageQuery, (data, id) => Carton.fromMap(data, id), rowPerLoad: 30); } void initUser(user) { super.initUser(user); } @override logout() async { getCartons?.close(); } Future deliver(Carton carton) { return Services.instance.cartonService.deliver(carton); } }