Untitled

mail@pastecode.io avatar
unknown
dart
2 years ago
1.6 kB
1
Indexable
Never
import 'package:get/get.dart';
import 'package:iketfaa_delivery/App/Common/Services/AuthenticationService/Core/manager.dart';
import 'package:iketfaa_delivery/App/Freelance/Models/Main/MyRequestsOrders.dart';

class FreelanceBookingController extends GetxController {
  final AuthenticationManager authManager = Get.find();
  RxList<MyRequestsOrders> myRequestsOrders = <MyRequestsOrders>[].obs;
  RxList<MyRequestsOrders> tempList = <MyRequestsOrders>[].obs;
  RxInt selectedStatus = 0.obs;
  RxInt currentTabIndex = 3.obs, currentServicesStatus = 1.obs;
  RxInt newItemCount = 0.obs;

  @override
  Future<void> onReady() async {
    getData();
    super.onReady();
  }

  Future<void> getData() async {
    tempList.clear();
    myRequestsOrders.clear();
    authManager.freelanceAPI
        .getAllRequestsOrders()
        .then((value) => myRequestsOrders.value = value);

    filterList(1);
  }

  void filterList(int status) {
    List<MyRequestsOrders> newBusinessServiceItems = <MyRequestsOrders>[];
    List<MyRequestsOrders> completedBusinessServiceItems = <MyRequestsOrders>[];
    tempList.clear();
    myRequestsOrders.where((p0) => p0.status == status).forEach((element) {
      tempList.add(element);
    });
    print(tempList.length);
    tempList.refresh();
    myRequestsOrders.where((p0) => p0.status == 1).forEach((element) {
      newBusinessServiceItems.add(element);
    });
    myRequestsOrders.where((p0) => p0.status == 3).forEach((element) {
      completedBusinessServiceItems.add(element);
    });
    newItemCount.value = newBusinessServiceItems.length;
  }
}