null safety
This commit is contained in:
@@ -135,7 +135,7 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
|
|||||||
final cartonTypeBox = LocalRadioButtons(
|
final cartonTypeBox = LocalRadioButtons(
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
values: cartonModel.cartonTypesInfo,
|
values: cartonModel.cartonTypesInfo,
|
||||||
selectedValue: _box.isShipmentCarton ?? false
|
selectedValue: (_box.isShipmentCarton ?? false)
|
||||||
? carton_from_shipments
|
? carton_from_shipments
|
||||||
: _box.cartonType);
|
: _box.cartonType);
|
||||||
final shipmentBox = DisplayText(
|
final shipmentBox = DisplayText(
|
||||||
|
|||||||
@@ -14,18 +14,18 @@ class DeliveryModel extends BaseModel {
|
|||||||
List<Carton> get cartons =>
|
List<Carton> get cartons =>
|
||||||
_selectedIndex == 1 ? _cartons : List<Carton>.from(_delivered.values);
|
_selectedIndex == 1 ? _cartons : List<Carton>.from(_delivered.values);
|
||||||
|
|
||||||
Paginator _delivered;
|
late Paginator _delivered;
|
||||||
int _selectedIndex = 1;
|
int _selectedIndex = 1;
|
||||||
bool isLoading = false;
|
bool isLoading = false;
|
||||||
List<Carton> _cartons = [];
|
List<Carton> _cartons = [];
|
||||||
StreamSubscription<QuerySnapshot> listener;
|
StreamSubscription<QuerySnapshot>? listener;
|
||||||
|
|
||||||
set selectedIndex(int index) {
|
set selectedIndex(int index) {
|
||||||
_selectedIndex = index;
|
_selectedIndex = index;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
get selectedIndex => _selectedIndex;
|
int get selectedIndex => _selectedIndex;
|
||||||
|
|
||||||
initData() {
|
initData() {
|
||||||
_selectedIndex = 1;
|
_selectedIndex = 1;
|
||||||
@@ -37,9 +37,9 @@ class DeliveryModel extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadCartons() async {
|
Future<void> _loadCartons() async {
|
||||||
if (user == null || !user.hasDeliveries()) return;
|
if (user == null || !user!.hasDeliveries()) return;
|
||||||
String path = "/$cartons_collection/";
|
String path = "/$cartons_collection/";
|
||||||
if (listener != null) listener.cancel();
|
if (listener != null) listener!.cancel();
|
||||||
_cartons = [];
|
_cartons = [];
|
||||||
try {
|
try {
|
||||||
listener = FirebaseFirestore.instance
|
listener = FirebaseFirestore.instance
|
||||||
@@ -55,9 +55,9 @@ class DeliveryModel extends BaseModel {
|
|||||||
.snapshots()
|
.snapshots()
|
||||||
.listen((QuerySnapshot snapshot) {
|
.listen((QuerySnapshot snapshot) {
|
||||||
_cartons.clear();
|
_cartons.clear();
|
||||||
_cartons = snapshot.documents.map((documentSnapshot) {
|
_cartons = snapshot.docs.map((documentSnapshot) {
|
||||||
var s = Carton.fromMap(
|
var s = Carton.fromMap(
|
||||||
documentSnapshot.data, documentSnapshot.documentID);
|
documentSnapshot.data as Map<String, dynamic>, documentSnapshot.id);
|
||||||
return s;
|
return s;
|
||||||
}).toList();
|
}).toList();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@@ -68,9 +68,9 @@ class DeliveryModel extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Paginator _getDelivered() {
|
Paginator _getDelivered() {
|
||||||
if (user == null || !user.hasDeliveries()) return null;
|
if (user == null || !user!.hasDeliveries()) throw "No Privilege";
|
||||||
|
|
||||||
var pageQuery = Firestore.instance
|
var pageQuery = FirebaseFirestore.instance
|
||||||
.collection("/$cartons_collection")
|
.collection("/$cartons_collection")
|
||||||
.where("is_delivered", isEqualTo: true)
|
.where("is_delivered", isEqualTo: true)
|
||||||
.where("status", whereIn: [carton_delivered_status]).where("is_deleted",
|
.where("status", whereIn: [carton_delivered_status]).where("is_deleted",
|
||||||
@@ -105,7 +105,7 @@ class DeliveryModel extends BaseModel {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
logout() async {
|
logout() async {
|
||||||
if (listener != null) await listener.cancel();
|
if (listener != null) await listener!.cancel();
|
||||||
if (_delivered != null) _delivered.close();
|
if (_delivered != null) _delivered.close();
|
||||||
_cartons = [];
|
_cartons = [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'package:barcode_scan2/gen/protos/protos.pb.dart';
|
||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
import 'package:fcs/data/services/services.dart';
|
import 'package:fcs/data/services/services.dart';
|
||||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||||
@@ -10,13 +11,13 @@ class DeliveryAddressModel extends BaseModel {
|
|||||||
final log = Logger('FcsShipmentModel');
|
final log = Logger('FcsShipmentModel');
|
||||||
List<DeliveryAddress> deliveryAddresses = [];
|
List<DeliveryAddress> deliveryAddresses = [];
|
||||||
|
|
||||||
StreamSubscription<QuerySnapshot> listener;
|
StreamSubscription<QuerySnapshot>? listener;
|
||||||
|
|
||||||
DeliveryAddress get defalutAddress =>
|
DeliveryAddress get defalutAddress =>
|
||||||
deliveryAddresses.firstWhere((e) => e.isDefault, orElse: () => null);
|
deliveryAddresses.firstWhere((e) => e.isDefault, orElse: () => DeliveryAddress());
|
||||||
|
|
||||||
DeliveryAddress getLocalDeliveryAddress(String id) =>
|
DeliveryAddress getLocalDeliveryAddress(String id) =>
|
||||||
deliveryAddresses.firstWhere((e) => e.id == id, orElse: () => null);
|
deliveryAddresses.firstWhere((e) => e.id == id, orElse: () => DeliveryAddress());
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void privilegeChanged() {
|
void privilegeChanged() {
|
||||||
@@ -26,26 +27,26 @@ class DeliveryAddressModel extends BaseModel {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
logout() async {
|
logout() async {
|
||||||
if (listener != null) await listener.cancel();
|
if (listener != null) await listener!.cancel();
|
||||||
deliveryAddresses = [];
|
deliveryAddresses = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadDeliveryAddresses() async {
|
Future<void> _loadDeliveryAddresses() async {
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
String path = "$delivery_address_collection/";
|
String path = "$delivery_address_collection/";
|
||||||
if (listener != null) listener.cancel();
|
if (listener != null) listener!.cancel();
|
||||||
deliveryAddresses = [];
|
deliveryAddresses = [];
|
||||||
try {
|
try {
|
||||||
listener = Firestore.instance
|
listener = FirebaseFirestore.instance
|
||||||
.collection('users')
|
.collection('users')
|
||||||
.document("${user.id}")
|
.doc("${user!.id}")
|
||||||
.collection("$path")
|
.collection("$path")
|
||||||
.snapshots()
|
.snapshots()
|
||||||
.listen((QuerySnapshot snapshot) {
|
.listen((QuerySnapshot snapshot) {
|
||||||
deliveryAddresses.clear();
|
deliveryAddresses.clear();
|
||||||
deliveryAddresses = snapshot.documents.map((documentSnapshot) {
|
deliveryAddresses = snapshot.docs.map((documentSnapshot) {
|
||||||
var s = DeliveryAddress.fromMap(
|
var s = DeliveryAddress.fromMap(
|
||||||
documentSnapshot.data, documentSnapshot.documentID);
|
documentSnapshot.data as Map<String,dynamic>, documentSnapshot.id);
|
||||||
return s;
|
return s;
|
||||||
}).toList();
|
}).toList();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@@ -56,9 +57,9 @@ class DeliveryAddressModel extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<DeliveryAddress> getDeliveryAddress(String id) async {
|
Future<DeliveryAddress> getDeliveryAddress(String id) async {
|
||||||
String path = "/$user_collection/${user.id}/$delivery_address_collection";
|
String path = "/$user_collection/${user!.id}/$delivery_address_collection";
|
||||||
var snap = await Firestore.instance.collection(path).document(id).get();
|
var snap = await FirebaseFirestore.instance.collection(path).doc(id).get();
|
||||||
return DeliveryAddress.fromMap(snap.data, snap.documentID);
|
return DeliveryAddress.fromMap(snap.data as Map<String,dynamic>, snap.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void initUser(user) {
|
void initUser(user) {
|
||||||
@@ -87,14 +88,14 @@ class DeliveryAddressModel extends BaseModel {
|
|||||||
|
|
||||||
Future<List<DeliveryAddress>> getDeliveryAddresses(String userID) async {
|
Future<List<DeliveryAddress>> getDeliveryAddresses(String userID) async {
|
||||||
String path = "$delivery_address_collection/";
|
String path = "$delivery_address_collection/";
|
||||||
var querySnap = await Firestore.instance
|
var querySnap = await FirebaseFirestore.instance
|
||||||
.collection('users')
|
.collection('users')
|
||||||
.document("$userID")
|
.doc("$userID")
|
||||||
.collection("$path")
|
.collection("$path")
|
||||||
.orderBy("full_name")
|
.orderBy("full_name")
|
||||||
.getDocuments();
|
.get();
|
||||||
return querySnap.documents
|
return querySnap.docs
|
||||||
.map((e) => DeliveryAddress.fromMap(e.data, e.documentID))
|
.map((e) => DeliveryAddress.fromMap(e.data as Map<String,dynamic>, e.id))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,9 +30,7 @@ class DiscountModel extends BaseModel {
|
|||||||
initData() {
|
initData() {
|
||||||
_selectedIndex = 1;
|
_selectedIndex = 1;
|
||||||
_load();
|
_load();
|
||||||
|
if (_getUsed() != null) _used = _getUsed();
|
||||||
if (_used != null) _used.close();
|
|
||||||
if (_getUsed() != null) _used = _getUsed()!;
|
|
||||||
_used.load();
|
_used.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,14 +42,14 @@ class DiscountModel extends BaseModel {
|
|||||||
_load() {
|
_load() {
|
||||||
if (listener != null) listener!.cancel();
|
if (listener != null) listener!.cancel();
|
||||||
try {
|
try {
|
||||||
listener = Firestore.instance
|
listener = FirebaseFirestore.instance
|
||||||
.collection("/$discounts_collection")
|
.collection("/$discounts_collection")
|
||||||
.orderBy("code", descending: false)
|
.orderBy("code", descending: false)
|
||||||
.snapshots()
|
.snapshots()
|
||||||
.listen((snaps) {
|
.listen((snaps) {
|
||||||
_discounts.clear();
|
_discounts.clear();
|
||||||
snaps.documents.forEach((d) {
|
snaps.docs.forEach((d) {
|
||||||
_discounts.add(Discount.fromMap(d.data, d.documentID));
|
_discounts.add(Discount.fromMap(d.data as Map<String,dynamic>, d.id));
|
||||||
});
|
});
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
});
|
});
|
||||||
@@ -60,10 +58,10 @@ class DiscountModel extends BaseModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Paginator? _getUsed() {
|
Paginator _getUsed() {
|
||||||
if (user == null || !user.hasFcsShipments()) return null;
|
if (user == null || !user!.hasFcsShipments()) throw "No Privilege";
|
||||||
|
|
||||||
var pageQuery = Firestore.instance
|
var pageQuery = FirebaseFirestore.instance
|
||||||
.collection("/$discounts_collection")
|
.collection("/$discounts_collection")
|
||||||
.where("status", isEqualTo: fcs_shipment_shipped_status)
|
.where("status", isEqualTo: fcs_shipment_shipped_status)
|
||||||
.orderBy("code", descending: false);
|
.orderBy("code", descending: false);
|
||||||
@@ -73,17 +71,17 @@ class DiscountModel extends BaseModel {
|
|||||||
return paginator;
|
return paginator;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Discount>?> getDiscount(String userID) async {
|
Future<List<Discount?>?> getDiscount(String userID) async {
|
||||||
String path = "/$discounts_collection";
|
String path = "/$discounts_collection";
|
||||||
try {
|
try {
|
||||||
var q = Firestore.instance
|
var q = FirebaseFirestore.instance
|
||||||
.collection("$path")
|
.collection("$path")
|
||||||
.where("customer_id", isEqualTo: userID)
|
.where("customer_id", isEqualTo: userID)
|
||||||
.where("status", isEqualTo: "available");
|
.where("status", isEqualTo: "available");
|
||||||
var snaps = await q.getDocuments(source: Source.server);
|
var snaps = await q.get(const GetOptions(source: Source.server));
|
||||||
List<Discount> discounts = snaps.documents.map((snap) {
|
var discounts = snaps.docs.map((snap) {
|
||||||
if (snap.exists) {
|
if (snap.exists) {
|
||||||
var s = Discount.fromMap(snap.data, snap.documentID);
|
var s = Discount.fromMap(snap.data as Map<String,dynamic>, snap.id);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}).toList();
|
}).toList();
|
||||||
@@ -128,6 +126,6 @@ class DiscountModel extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deleteDiscount(Discount discount) async {
|
Future<void> deleteDiscount(Discount discount) async {
|
||||||
return Services.instance.commonService.deleteDiscount(discount.id);
|
return Services.instance.commonService.deleteDiscount(discount.id!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,22 +12,22 @@ class FAQModel extends BaseModel {
|
|||||||
List<FAQ> faqs = [];
|
List<FAQ> faqs = [];
|
||||||
|
|
||||||
FAQ getFAQ(String id) {
|
FAQ getFAQ(String id) {
|
||||||
return faqs.firstWhere((e) => e.id == id, orElse: () => null);
|
return faqs.firstWhere((e) => e.id == id, orElse: () => FAQ());
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamSubscription<QuerySnapshot> listener;
|
StreamSubscription<QuerySnapshot>? listener;
|
||||||
|
|
||||||
FAQModel() {
|
FAQModel() {
|
||||||
if (listener != null) listener.cancel();
|
if (listener != null) listener!.cancel();
|
||||||
try {
|
try {
|
||||||
listener = Firestore.instance
|
listener = FirebaseFirestore.instance
|
||||||
.collection("/faqs")
|
.collection("/faqs")
|
||||||
.orderBy("sn", descending: false)
|
.orderBy("sn", descending: false)
|
||||||
.snapshots()
|
.snapshots()
|
||||||
.listen((snaps) {
|
.listen((snaps) {
|
||||||
faqs.clear();
|
faqs.clear();
|
||||||
snaps.documents.forEach((d) {
|
snaps.docs.forEach((d) {
|
||||||
faqs.add(FAQ.fromMap(d.data, d.documentID));
|
faqs.add(FAQ.fromMap(d.data as Map<String,dynamic>, d.id));
|
||||||
});
|
});
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
|
|||||||
_destinationController.text = _shipment.destination ?? "";
|
_destinationController.text = _shipment.destination ?? "";
|
||||||
} else {
|
} else {
|
||||||
var mainModel = Provider.of<MainModel>(context, listen: false);
|
var mainModel = Provider.of<MainModel>(context, listen: false);
|
||||||
_currentShipmentType = mainModel.setting.shipmentTypes[0];
|
_currentShipmentType = mainModel.setting!.shipmentTypes[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
|
|||||||
labelText: AppTranslations.of(context)!
|
labelText: AppTranslations.of(context)!
|
||||||
.text('FCSshipment.shipment_type'),
|
.text('FCSshipment.shipment_type'),
|
||||||
icon: Icon(Ionicons.ios_airplane, color: primaryColor)),
|
icon: Icon(Ionicons.ios_airplane, color: primaryColor)),
|
||||||
items: mainModel.setting.shipmentTypes
|
items: mainModel.setting!.shipmentTypes
|
||||||
.map((e) => DropdownMenuItem(child: Text(e), value: e))
|
.map((e) => DropdownMenuItem(child: Text(e), value: e))
|
||||||
.toList(),
|
.toList(),
|
||||||
onChanged: (String? selected) => {
|
onChanged: (String? selected) => {
|
||||||
@@ -288,7 +288,7 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
|
|||||||
_consigneeController.text != "" ||
|
_consigneeController.text != "" ||
|
||||||
_portController.text != "" ||
|
_portController.text != "" ||
|
||||||
_destinationController.text != "" ||
|
_destinationController.text != "" ||
|
||||||
_currentShipmentType != mainModel.setting.shipmentTypes[0];
|
_currentShipmentType != mainModel.setting!.shipmentTypes[0];
|
||||||
} else {
|
} else {
|
||||||
FcsShipment fcsShipment = _getPayload();
|
FcsShipment fcsShipment = _getPayload();
|
||||||
return widget.shipment!.isChangedForEdit(fcsShipment);
|
return widget.shipment!.isChangedForEdit(fcsShipment);
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ import 'package:logging/logging.dart';
|
|||||||
class FcsShipmentModel extends BaseModel {
|
class FcsShipmentModel extends BaseModel {
|
||||||
final log = Logger('FcsShipmentModel');
|
final log = Logger('FcsShipmentModel');
|
||||||
|
|
||||||
StreamSubscription<QuerySnapshot> listener;
|
StreamSubscription<QuerySnapshot>? listener;
|
||||||
List<FcsShipment> _fcsShipments = [];
|
List<FcsShipment> _fcsShipments = [];
|
||||||
List<FcsShipment> get fcsShipments => _selectedIndex == 1
|
List<FcsShipment> get fcsShipments => _selectedIndex == 1
|
||||||
? _fcsShipments
|
? _fcsShipments
|
||||||
: List<FcsShipment>.from(_shipped.values);
|
: List<FcsShipment>.from(_shipped.values);
|
||||||
|
|
||||||
Paginator _shipped;
|
late Paginator _shipped;
|
||||||
bool isLoading = false;
|
bool isLoading = false;
|
||||||
int _selectedIndex = 1;
|
int _selectedIndex = 1;
|
||||||
set selectedIndex(int index) {
|
set selectedIndex(int index) {
|
||||||
@@ -25,7 +25,7 @@ class FcsShipmentModel extends BaseModel {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
get selectedIndex => _selectedIndex;
|
int get selectedIndex => _selectedIndex;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void privilegeChanged() {
|
void privilegeChanged() {
|
||||||
@@ -43,12 +43,12 @@ class FcsShipmentModel extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadFcsShipments() async {
|
Future<void> _loadFcsShipments() async {
|
||||||
if (user == null || !user.hasFcsShipments()) return;
|
if (user == null || !user!.hasFcsShipments()) throw "No Privilege";
|
||||||
String path = "/$fcs_shipment_collection/";
|
String path = "/$fcs_shipment_collection/";
|
||||||
if (listener != null) listener.cancel();
|
if (listener != null) listener!.cancel();
|
||||||
_fcsShipments = [];
|
_fcsShipments = [];
|
||||||
try {
|
try {
|
||||||
listener = Firestore.instance
|
listener = FirebaseFirestore.instance
|
||||||
.collection("$path")
|
.collection("$path")
|
||||||
.where("status", isEqualTo: fcs_shipment_confirmed_status)
|
.where("status", isEqualTo: fcs_shipment_confirmed_status)
|
||||||
.where("is_deleted", isEqualTo: false)
|
.where("is_deleted", isEqualTo: false)
|
||||||
@@ -56,9 +56,9 @@ class FcsShipmentModel extends BaseModel {
|
|||||||
.snapshots()
|
.snapshots()
|
||||||
.listen((QuerySnapshot snapshot) {
|
.listen((QuerySnapshot snapshot) {
|
||||||
_fcsShipments.clear();
|
_fcsShipments.clear();
|
||||||
_fcsShipments = snapshot.documents.map((documentSnapshot) {
|
_fcsShipments = snapshot.docs.map((documentSnapshot) {
|
||||||
var s = FcsShipment.fromMap(
|
var s = FcsShipment.fromMap(
|
||||||
documentSnapshot.data, documentSnapshot.documentID);
|
documentSnapshot.data as Map<String,dynamic>, documentSnapshot.id);
|
||||||
return s;
|
return s;
|
||||||
}).toList();
|
}).toList();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@@ -69,9 +69,9 @@ class FcsShipmentModel extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Paginator _getShipped() {
|
Paginator _getShipped() {
|
||||||
if (user == null || !user.hasFcsShipments()) return null;
|
if (user == null || !user!.hasFcsShipments()) throw "No Privilege";
|
||||||
|
|
||||||
var pageQuery = Firestore.instance
|
var pageQuery = FirebaseFirestore.instance
|
||||||
.collection("/$fcs_shipment_collection")
|
.collection("/$fcs_shipment_collection")
|
||||||
.where("status", isEqualTo: fcs_shipment_shipped_status)
|
.where("status", isEqualTo: fcs_shipment_shipped_status)
|
||||||
.where("is_deleted", isEqualTo: false)
|
.where("is_deleted", isEqualTo: false)
|
||||||
@@ -102,13 +102,13 @@ class FcsShipmentModel extends BaseModel {
|
|||||||
Future<List<FcsShipment>> getActiveFcsShipments() async {
|
Future<List<FcsShipment>> getActiveFcsShipments() async {
|
||||||
List<FcsShipment> fcsShipments = [];
|
List<FcsShipment> fcsShipments = [];
|
||||||
try {
|
try {
|
||||||
var snaps = await Firestore.instance
|
var snaps = await FirebaseFirestore.instance
|
||||||
.collection("/$fcs_shipment_collection")
|
.collection("/$fcs_shipment_collection")
|
||||||
.where("status", isEqualTo: fcs_shipment_confirmed_status)
|
.where("status", isEqualTo: fcs_shipment_confirmed_status)
|
||||||
.getDocuments(source: Source.server);
|
.get(const GetOptions(source: Source.server));
|
||||||
fcsShipments = snaps.documents.map((documentSnapshot) {
|
fcsShipments = snaps.docs.map((documentSnapshot) {
|
||||||
var fcs = FcsShipment.fromMap(
|
var fcs = FcsShipment.fromMap(
|
||||||
documentSnapshot.data, documentSnapshot.documentID);
|
documentSnapshot.data as Map<String,dynamic>, documentSnapshot.id);
|
||||||
return fcs;
|
return fcs;
|
||||||
}).toList();
|
}).toList();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -117,13 +117,13 @@ class FcsShipmentModel extends BaseModel {
|
|||||||
return fcsShipments;
|
return fcsShipments;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<FcsShipment> getFcsShipment(String id) async {
|
Future<FcsShipment?> getFcsShipment(String id) async {
|
||||||
try {
|
try {
|
||||||
var snap = await Firestore.instance
|
var snap = await FirebaseFirestore.instance
|
||||||
.collection("/$fcs_shipment_collection")
|
.collection("/$fcs_shipment_collection")
|
||||||
.document(id)
|
.doc(id)
|
||||||
.get(source: Source.server);
|
.get(const GetOptions(source: Source.server));
|
||||||
var fcs = FcsShipment.fromMap(snap.data, snap.documentID);
|
var fcs = FcsShipment.fromMap(snap.data as Map<String,dynamic>, snap.id);
|
||||||
|
|
||||||
return fcs;
|
return fcs;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -135,13 +135,13 @@ class FcsShipmentModel extends BaseModel {
|
|||||||
Future<List<FcsShipment>> getInvoiceFcsShipments() async {
|
Future<List<FcsShipment>> getInvoiceFcsShipments() async {
|
||||||
List<FcsShipment> fcsShipments = [];
|
List<FcsShipment> fcsShipments = [];
|
||||||
try {
|
try {
|
||||||
var snaps = await Firestore.instance
|
var snaps = await FirebaseFirestore.instance
|
||||||
.collection("/$fcs_shipment_collection")
|
.collection("/$fcs_shipment_collection")
|
||||||
.where("pending_invoice_user_count", isGreaterThan: 0)
|
.where("pending_invoice_user_count", isGreaterThan: 0)
|
||||||
.getDocuments(source: Source.server);
|
.get(const GetOptions(source: Source.server));
|
||||||
fcsShipments = snaps.documents.map((documentSnapshot) {
|
fcsShipments = snaps.docs.map((documentSnapshot) {
|
||||||
var fcs = FcsShipment.fromMap(
|
var fcs = FcsShipment.fromMap(
|
||||||
documentSnapshot.data, documentSnapshot.documentID);
|
documentSnapshot.data as Map<String,dynamic>, documentSnapshot.id);
|
||||||
return fcs;
|
return fcs;
|
||||||
}).toList();
|
}).toList();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -156,7 +156,7 @@ class FcsShipmentModel extends BaseModel {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
logout() async {
|
logout() async {
|
||||||
if (listener != null) await listener.cancel();
|
if (listener != null) await listener!.cancel();
|
||||||
if (_shipped != null) _shipped.close();
|
if (_shipped != null) _shipped.close();
|
||||||
_fcsShipments = [];
|
_fcsShipments = [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class InvoiceDiscountList extends StatelessWidget {
|
class InvoiceDiscountList extends StatelessWidget {
|
||||||
final List<Discount>? discounts;
|
final List<Discount?>? discounts;
|
||||||
|
|
||||||
const InvoiceDiscountList({
|
const InvoiceDiscountList({
|
||||||
Key? key,
|
Key? key,
|
||||||
@@ -68,14 +68,14 @@ class InvoiceDiscountList extends StatelessWidget {
|
|||||||
onSelectChanged: (value) => Navigator.pop(context, c),
|
onSelectChanged: (value) => Navigator.pop(context, c),
|
||||||
cells: [
|
cells: [
|
||||||
MyDataCell(new Text(
|
MyDataCell(new Text(
|
||||||
c.code!,
|
c?.code ?? '',
|
||||||
style: textStyle,
|
style: textStyle,
|
||||||
)),
|
)),
|
||||||
MyDataCell(
|
MyDataCell(
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
Text(c.amount.toStringAsFixed(2), style: textStyle),
|
Text(c?.amount.toStringAsFixed(2) ?? "", style: textStyle),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Discount> discounts = [];
|
List<Discount?> discounts = [];
|
||||||
_loadDiscount() async {
|
_loadDiscount() async {
|
||||||
DiscountModel discountModel =
|
DiscountModel discountModel =
|
||||||
Provider.of<DiscountModel>(context, listen: false);
|
Provider.of<DiscountModel>(context, listen: false);
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import 'package:logging/logging.dart';
|
|||||||
|
|
||||||
class StaffModel extends BaseModel {
|
class StaffModel extends BaseModel {
|
||||||
final log = Logger('StaffModel');
|
final log = Logger('StaffModel');
|
||||||
StreamSubscription<QuerySnapshot> listener;
|
StreamSubscription<QuerySnapshot>? listener;
|
||||||
StreamSubscription<QuerySnapshot> privilegeListener;
|
StreamSubscription<QuerySnapshot>? privilegeListener;
|
||||||
|
|
||||||
List<User> employees = [];
|
List<User> employees = [];
|
||||||
List<Privilege> privileges = [];
|
List<Privilege> privileges = [];
|
||||||
@@ -26,28 +26,28 @@ class StaffModel extends BaseModel {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
logout() async {
|
logout() async {
|
||||||
if (listener != null) listener.cancel();
|
if (listener != null) listener!.cancel();
|
||||||
if (privilegeListener != null) privilegeListener.cancel();
|
if (privilegeListener != null) privilegeListener!.cancel();
|
||||||
employees = [];
|
employees = [];
|
||||||
privileges = [];
|
privileges = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadEmployees() async {
|
Future<void> _loadEmployees() async {
|
||||||
if (user == null || !user.hasStaffs()) return;
|
if (user == null || !user!.hasStaffs()) throw "No Privilege";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (listener != null) listener.cancel();
|
if (listener != null) listener!.cancel();
|
||||||
|
|
||||||
listener = Firestore.instance
|
listener = FirebaseFirestore.instance
|
||||||
.collection("/$user_collection")
|
.collection("/$user_collection")
|
||||||
.where("is_employee", isEqualTo: true)
|
.where("is_employee", isEqualTo: true)
|
||||||
.where("is_sys_admin", isEqualTo: false)
|
.where("is_sys_admin", isEqualTo: false)
|
||||||
.snapshots()
|
.snapshots()
|
||||||
.listen((QuerySnapshot snapshot) {
|
.listen((QuerySnapshot snapshot) {
|
||||||
employees.clear();
|
employees.clear();
|
||||||
employees = snapshot.documents.map((documentSnapshot) {
|
employees = snapshot.docs.map((documentSnapshot) {
|
||||||
var user =
|
var user =
|
||||||
User.fromMap(documentSnapshot.data, documentSnapshot.documentID);
|
User.fromMap(documentSnapshot.data as Map<String,dynamic>, documentSnapshot.id);
|
||||||
return user;
|
return user;
|
||||||
}).toList();
|
}).toList();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@@ -59,14 +59,14 @@ class StaffModel extends BaseModel {
|
|||||||
|
|
||||||
Future<void> _loadPrivileges() async {
|
Future<void> _loadPrivileges() async {
|
||||||
try {
|
try {
|
||||||
privilegeListener = Firestore.instance
|
privilegeListener = FirebaseFirestore.instance
|
||||||
.collection("/$privilege_collection")
|
.collection("/$privilege_collection")
|
||||||
.snapshots()
|
.snapshots()
|
||||||
.listen((QuerySnapshot snapshot) {
|
.listen((QuerySnapshot snapshot) {
|
||||||
privileges.clear();
|
privileges.clear();
|
||||||
privileges = snapshot.documents.map((documentSnapshot) {
|
privileges = snapshot.docs.map((documentSnapshot) {
|
||||||
var privilege = Privilege.fromMap(
|
var privilege = Privilege.fromMap(
|
||||||
documentSnapshot.data, documentSnapshot.documentID);
|
documentSnapshot.data as Map<String,dynamic>, documentSnapshot.id);
|
||||||
return privilege;
|
return privilege;
|
||||||
}).toList();
|
}).toList();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@@ -82,27 +82,27 @@ class StaffModel extends BaseModel {
|
|||||||
token: await getToken());
|
token: await getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<User> findUser(String phoneNumber) {
|
Future<User?> findUser(String phoneNumber) {
|
||||||
return Services.instance.userService.findUser(phoneNumber);
|
return Services.instance.userService.findUser(phoneNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<User>> getPickupEmployees() async {
|
Future<List<User>> getPickupEmployees() async {
|
||||||
if (user == null || !user.hasShipment()) return [];
|
if (user == null || !user!.hasShipment()) return [];
|
||||||
return _getUsers(privilege_shipment);
|
return _getUsers(privilege_shipment);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<User>> _getUsers(String privilege) async {
|
Future<List<User>> _getUsers(String privilege) async {
|
||||||
List<User> users = [];
|
List<User> users = [];
|
||||||
try {
|
try {
|
||||||
var snaps = await Firestore.instance
|
var snaps = await FirebaseFirestore.instance
|
||||||
.collection("/$user_collection")
|
.collection("/$user_collection")
|
||||||
.where("is_employee", isEqualTo: true)
|
.where("is_employee", isEqualTo: true)
|
||||||
.where("is_sys_admin", isEqualTo: false)
|
.where("is_sys_admin", isEqualTo: false)
|
||||||
.where("privileges", arrayContains: privilege)
|
.where("privileges", arrayContains: privilege)
|
||||||
.getDocuments(source: Source.server);
|
.get(const GetOptions(source: Source.server));
|
||||||
users = snaps.documents.map((documentSnapshot) {
|
users = snaps.docs.map((documentSnapshot) {
|
||||||
var user =
|
var user =
|
||||||
User.fromMap(documentSnapshot.data, documentSnapshot.documentID);
|
User.fromMap(documentSnapshot.data as Map<String,dynamic>, documentSnapshot.id);
|
||||||
return user;
|
return user;
|
||||||
}).toList();
|
}).toList();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ class _StaffEditorState extends State<StaffEditor> {
|
|||||||
_isLoading = true;
|
_isLoading = true;
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
User _user = await staffModel.findUser(_phoneInput.text);
|
User? _user = await staffModel.findUser(_phoneInput.text);
|
||||||
if (_user == null) {
|
if (_user == null) {
|
||||||
showMsgDialog(context, "Error", _phoneInput.text + " not found!");
|
showMsgDialog(context, "Error", _phoneInput.text + " not found!");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class _LocalPopupMenuButtonState extends State<LocalPopupMenuButton> {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Icon(
|
Icon(
|
||||||
widget.buttonIcon ?? Icons.filter_list,
|
widget.buttonIcon ?? Icons.filter_list,
|
||||||
color: widget.buttonColor ?? primaryColor,
|
color: widget.buttonColor,
|
||||||
),
|
),
|
||||||
hightlight
|
hightlight
|
||||||
? Positioned(
|
? Positioned(
|
||||||
@@ -98,14 +98,12 @@ class _LocalPopupMenuButtonState extends State<LocalPopupMenuButton> {
|
|||||||
)),
|
)),
|
||||||
itemBuilder: (BuildContext context) {
|
itemBuilder: (BuildContext context) {
|
||||||
return popmenus.map((LocalPopupMenu choice) {
|
return popmenus.map((LocalPopupMenu choice) {
|
||||||
if (choice == null) return null;
|
|
||||||
return PopupMenuItem<LocalPopupMenu>(
|
return PopupMenuItem<LocalPopupMenu>(
|
||||||
value: choice,
|
value: choice,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
LocalText(context, choice.textKey,
|
LocalText(context, choice.textKey ?? "",
|
||||||
color:
|
color: choice.enabled ? primaryColor : Colors.grey),
|
||||||
choice?.enabled ?? true ? primaryColor : Colors.grey),
|
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 10,
|
width: 10,
|
||||||
),
|
),
|
||||||
@@ -124,8 +122,8 @@ class _LocalPopupMenuButtonState extends State<LocalPopupMenuButton> {
|
|||||||
|
|
||||||
bool _needHighlight() {
|
bool _needHighlight() {
|
||||||
popmenus.forEach((e) {
|
popmenus.forEach((e) {
|
||||||
if (e == null) return false;
|
if (e == null) return;
|
||||||
if (e.selected && e.highlight) return true;
|
if (e.selected && e.highlight) return;
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user