add cartonsize api
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/carton_size.dart';
|
||||
import 'package:fcs/helpers/firebase_helper.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
@@ -20,26 +22,49 @@ class CartonSizeModel extends BaseModel {
|
||||
|
||||
void initUser(user) {
|
||||
super.initUser(user);
|
||||
cartonSizes = [
|
||||
CartonSize(
|
||||
id: "1", name: "FCS Small Box", length: 16, width: 12, height: 12),
|
||||
CartonSize(
|
||||
id: "2", name: "FCS Medium Box", length: 22, width: 16, height: 15),
|
||||
CartonSize(
|
||||
id: "3", name: "FCS Large Box", length: 28, width: 15, height: 16)
|
||||
];
|
||||
_loadCartonSizes();
|
||||
}
|
||||
|
||||
Future<void> _loadCartonSizes() async {
|
||||
try {
|
||||
if (listener != null) listener.cancel();
|
||||
|
||||
listener = Firestore.instance
|
||||
.collection(
|
||||
"/$config_collection/$setting_doc_id/$carton_sizes_collection")
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
cartonSizes.clear();
|
||||
cartonSizes = snapshot.documents.map((documentSnapshot) {
|
||||
var c = CartonSize.fromMap(
|
||||
documentSnapshot.data, documentSnapshot.documentID);
|
||||
return c;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
});
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
logout() async {
|
||||
if (listener != null) await listener.cancel();
|
||||
|
||||
cartonSizes = [];
|
||||
}
|
||||
|
||||
Future<void> addCartonSize(CartonSize cartonSize) async {}
|
||||
Future<void> addCartonSize(CartonSize cartonSize) async {
|
||||
await request("/carton_sizes", "POST",
|
||||
payload: cartonSize.toMap(), token: await getToken());
|
||||
}
|
||||
|
||||
Future<void> updateCartonSize(CartonSize cartonSize) async {}
|
||||
Future<void> updateCartonSize(CartonSize cartonSize) async {
|
||||
await request("/carton_sizes", "PUT",
|
||||
payload: cartonSize.toMap(), token: await getToken());
|
||||
}
|
||||
|
||||
Future<void> deleteCartonSize(String id) async {}
|
||||
Future<void> deleteCartonSize(String id) async {
|
||||
await request("/carton_sizes", "DELETE",
|
||||
payload: {"id": id}, token: await getToken());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user