import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:sk_base_mobile/db_helper/dbHelper.dart'; import 'package:sk_base_mobile/util/date.util.dart'; import 'package:sk_base_mobile/util/modal.util.dart'; class HomeController extends GetxController { RxMap userData = {}.obs; RxInt currentIndex = 0.obs; final PageController pageController = PageController(); final DateTime dateTime = DateTime.now(); final DbHelper db = DbHelper(); List list = [ [].obs, [].obs, [].obs, [].obs, [].obs, [].obs, [].obs, ].obs; RxInt barIndex = 0.obs; RxList model = [].obs; final ScrollController scrollController = ScrollController(); HomeController() {} getTasks() async { db.getData().then((value) { model.value = value; getSepretLists(); }); } setIndex(int value) { pageController.animateToPage(value, duration: const Duration(milliseconds: 300), curve: Curves.easeIn); currentIndex.value = value; } getDateAccordingTabs(int value) { return '${DateUtil.addPrefix(dateTime.add(Duration(days: value)).day.toString())}/${DateUtil.addPrefix(dateTime.add(Duration(days: value)).month.toString())}/${DateUtil.addPrefix(dateTime.add(Duration(days: value)).year.toString())}'; } getSepretLists() { List> tempList = []; for (int i = 0; i < 7; i++) { RxList tempList1 = [].obs; tempList1.clear(); for (int j = 0; j < model.length; j++) { if (model[j].date == getDateAccordingTabs(i)) { tempList1.add(model[j]); } } tempList.add(tempList1); } list = tempList; } onMoveNextPage() { if (currentIndex.value < 7) { setIndex(currentIndex.value + 1); } } onMoveBack() { if (currentIndex.value > 0) { setIndex(currentIndex.value - 1); } } onTaskComplete( int value, int index, int ind, String key, BuildContext context) { switch (value) { case 3: { ModalUtil.showWarningDialog('Complete Task', 'This task will be marked as completed', 'Confirm', () { list[ind][index].status = 'complete'; list[ind].add(''); list[ind].remove(''); db.update(key, 'status', 'complete'); }); } case 2: { ModalUtil.showWarningDialog( 'Delete Task', 'Are you want to sure to remove', 'Confirm', () { list[ind].remove(list[ind][index]); db.delete( key, 'Tasks', ); }); } } } }