Refactor AttendanceScreen to improve project selection and refresh logic
This commit is contained in:
parent
2421233b9f
commit
501bec819f
@ -40,22 +40,6 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Layout(
|
||||
child: MyRefreshableContent(
|
||||
onRefresh: () async {
|
||||
if (attendanceController.selectedProjectId != null) {
|
||||
await attendanceController.fetchEmployeesByProject(
|
||||
attendanceController.selectedProjectId!);
|
||||
await attendanceController
|
||||
.fetchAttendanceLogs(attendanceController.selectedProjectId!);
|
||||
await attendanceController
|
||||
.fetchProjectData(attendanceController.selectedProjectId!);
|
||||
await attendanceController
|
||||
.fetchProjectData(attendanceController.selectedProjectId!);
|
||||
attendanceController.update();
|
||||
} else {
|
||||
await attendanceController.fetchProjects();
|
||||
}
|
||||
},
|
||||
child: GetBuilder<AttendanceController>(
|
||||
init: attendanceController,
|
||||
tag: 'attendance_dashboard_controller',
|
||||
@ -148,12 +132,10 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
},
|
||||
color: theme.cardTheme.color,
|
||||
child: Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
MyText.labelSmall(
|
||||
attendanceController.selectedProjectId !=
|
||||
null
|
||||
attendanceController.selectedProjectId != null
|
||||
? attendanceController.projects
|
||||
.firstWhereOrNull((proj) =>
|
||||
proj.id ==
|
||||
@ -199,8 +181,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
length: tabs.length,
|
||||
child: MyCard.bordered(
|
||||
borderRadiusAll: 4,
|
||||
border: Border.all(
|
||||
color: Colors.grey.withAlpha(50)),
|
||||
border:
|
||||
Border.all(color: Colors.grey.withAlpha(50)),
|
||||
shadow: MyShadow(
|
||||
elevation: 1,
|
||||
position: MyShadowPosition.bottom),
|
||||
@ -234,7 +216,6 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -365,15 +346,27 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
),
|
||||
]);
|
||||
}).toList();
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(0.0),
|
||||
child: SingleChildScrollView(
|
||||
child: MyRefreshableContent(
|
||||
onRefresh: () async {
|
||||
if (attendanceController.selectedProjectId != null) {
|
||||
await attendanceController.fetchEmployeesByProject(
|
||||
attendanceController.selectedProjectId!);
|
||||
await attendanceController
|
||||
.fetchProjectData(attendanceController.selectedProjectId!);
|
||||
attendanceController.update();
|
||||
} else {
|
||||
await attendanceController.fetchProjects();
|
||||
}
|
||||
},
|
||||
child: MyPaginatedTable(
|
||||
columns: columns,
|
||||
rows: rows,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -832,11 +825,28 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextButton.icon(
|
||||
child: GetBuilder<AttendanceController>(
|
||||
id: 'attendance_dashboard_controller',
|
||||
builder: (controller) {
|
||||
String labelText;
|
||||
if (controller.startDateAttendance != null &&
|
||||
controller.endDateAttendance != null) {
|
||||
final start = DateFormat('dd MM yyyy')
|
||||
.format(controller.startDateAttendance!);
|
||||
final end = DateFormat('dd MM yyyy')
|
||||
.format(controller.endDateAttendance!);
|
||||
labelText = "$start - $end";
|
||||
} else {
|
||||
labelText = "Select Date Range for Attendance";
|
||||
}
|
||||
|
||||
return TextButton.icon(
|
||||
icon: const Icon(Icons.date_range),
|
||||
label: const Text("Select Date Range for Attendance"),
|
||||
onPressed: () => attendanceController
|
||||
.selectDateRangeForAttendance(context, attendanceController),
|
||||
label: Text(labelText, overflow: TextOverflow.ellipsis),
|
||||
onPressed: () => controller.selectDateRangeForAttendance(
|
||||
Get.context!, controller),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
if (attendanceController.attendanceLogs.isEmpty)
|
||||
@ -851,12 +861,25 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
),
|
||||
)
|
||||
else
|
||||
SingleChildScrollView(
|
||||
MyRefreshableContent(
|
||||
onRefresh: () async {
|
||||
if (attendanceController.selectedProjectId != null) {
|
||||
await attendanceController.fetchAttendanceLogs(
|
||||
attendanceController.selectedProjectId!);
|
||||
await attendanceController.fetchProjectData(
|
||||
attendanceController.selectedProjectId!);
|
||||
attendanceController.update();
|
||||
} else {
|
||||
await attendanceController.fetchProjects();
|
||||
}
|
||||
},
|
||||
child: SingleChildScrollView(
|
||||
child: MyPaginatedTable(
|
||||
columns: columns,
|
||||
rows: rows,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -1120,6 +1143,18 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
)
|
||||
else
|
||||
Expanded(
|
||||
child: MyRefreshableContent(
|
||||
onRefresh: () async {
|
||||
if (attendanceController.selectedProjectId != null) {
|
||||
await attendanceController.fetchProjectData(
|
||||
attendanceController.selectedProjectId!);
|
||||
await attendanceController.fetchRegularizationLogs(
|
||||
attendanceController.selectedProjectId!);
|
||||
attendanceController.update();
|
||||
} else {
|
||||
await attendanceController.fetchProjects();
|
||||
}
|
||||
},
|
||||
child: SingleChildScrollView(
|
||||
child: MyPaginatedTable(
|
||||
columns: columns,
|
||||
@ -1128,6 +1163,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user