mobile_skt/lib/screens/home/home_controller.dart

100 lines
2.6 KiB
Dart
Raw Normal View History

2024-03-19 11:09:07 +08:00
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sk_base_mobile/db_helper/dbHelper.dart';
2024-03-19 13:27:42 +08:00
import 'package:sk_base_mobile/util/date.util.dart';
2024-03-19 11:09:07 +08:00
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<RxList> list = [
[].obs,
[].obs,
[].obs,
[].obs,
[].obs,
[].obs,
[].obs,
].obs;
RxInt barIndex = 0.obs;
RxList model = [].obs;
final ScrollController scrollController = ScrollController();
2024-03-19 13:27:42 +08:00
HomeController() {}
2024-03-19 11:09:07 +08:00
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;
}
2024-03-19 13:27:42 +08:00
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())}';
}
2024-03-19 11:09:07 +08:00
getSepretLists() {
2024-03-19 13:27:42 +08:00
List<RxList<dynamic>> 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;
2024-03-19 11:09:07 +08:00
}
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',
);
});
}
}
}
}