- Implemented employee skeleton card for loading states in the UI. - Created AssignedProjectsResponse and AssignedProject models for handling project assignments. - Enhanced EmployeeDetailBottomSheet to include project assignment button. - Developed AssignProjectBottomSheet for selecting projects to assign to employees. - Introduced EmployeeDetailPage for displaying detailed employee information. - Updated EmployeesScreen to support searching and filtering employees. - Improved layout and UI elements for better user experience.
528 lines
22 KiB
Dart
528 lines
22 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:marco/helpers/theme/app_theme.dart';
|
|
import 'package:marco/helpers/utils/mixins/ui_mixin.dart';
|
|
import 'package:marco/helpers/widgets/my_spacing.dart';
|
|
import 'package:marco/helpers/widgets/my_text.dart';
|
|
import 'package:marco/controller/permission_controller.dart';
|
|
import 'package:marco/model/employees/add_employee_bottom_sheet.dart';
|
|
import 'package:marco/controller/dashboard/employees_screen_controller.dart';
|
|
import 'package:marco/helpers/widgets/avatar.dart';
|
|
import 'package:marco/controller/project_controller.dart';
|
|
import 'package:marco/helpers/widgets/my_custom_skeleton.dart';
|
|
import 'package:marco/view/employees/employee_detail_screen.dart';
|
|
import 'package:marco/model/employee_model.dart';
|
|
import 'package:marco/helpers/utils/launcher_utils.dart';
|
|
|
|
class EmployeesScreen extends StatefulWidget {
|
|
const EmployeesScreen({super.key});
|
|
|
|
@override
|
|
State<EmployeesScreen> createState() => _EmployeesScreenState();
|
|
}
|
|
|
|
class _EmployeesScreenState extends State<EmployeesScreen> with UIMixin {
|
|
final EmployeesScreenController employeeScreenController =
|
|
Get.put(EmployeesScreenController());
|
|
final PermissionController permissionController =
|
|
Get.put(PermissionController());
|
|
|
|
final TextEditingController _searchController = TextEditingController();
|
|
final RxList<EmployeeModel> _filteredEmployees = <EmployeeModel>[].obs;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
final selectedProjectId =
|
|
Get.find<ProjectController>().selectedProject?.id;
|
|
|
|
if (selectedProjectId != null) {
|
|
employeeScreenController.selectedProjectId = selectedProjectId;
|
|
employeeScreenController.fetchEmployeesByProject(selectedProjectId);
|
|
} else if (employeeScreenController.isAllEmployeeSelected.value) {
|
|
employeeScreenController.selectedProjectId = null;
|
|
employeeScreenController.fetchAllEmployees();
|
|
} else {
|
|
employeeScreenController.clearEmployees();
|
|
}
|
|
|
|
_searchController.addListener(() {
|
|
_filterEmployees(_searchController.text);
|
|
});
|
|
});
|
|
}
|
|
|
|
Future<void> _refreshEmployees() async {
|
|
try {
|
|
final selectedProjectId =
|
|
Get.find<ProjectController>().selectedProject?.id;
|
|
final isAllSelected =
|
|
employeeScreenController.isAllEmployeeSelected.value;
|
|
|
|
if (isAllSelected) {
|
|
employeeScreenController.selectedProjectId = null;
|
|
await employeeScreenController.fetchAllEmployees();
|
|
} else if (selectedProjectId != null) {
|
|
employeeScreenController.selectedProjectId = selectedProjectId;
|
|
await employeeScreenController
|
|
.fetchEmployeesByProject(selectedProjectId);
|
|
} else {
|
|
employeeScreenController.clearEmployees();
|
|
}
|
|
|
|
_filterEmployees(_searchController.text);
|
|
employeeScreenController.update(['employee_screen_controller']);
|
|
} catch (e, stackTrace) {
|
|
debugPrint('Error refreshing employee data: ${e.toString()}');
|
|
debugPrintStack(stackTrace: stackTrace);
|
|
}
|
|
}
|
|
|
|
void _filterEmployees(String query) {
|
|
final employees = employeeScreenController.employees;
|
|
if (query.isEmpty) {
|
|
_filteredEmployees.assignAll(employees);
|
|
} else {
|
|
final lowerQuery = query.toLowerCase();
|
|
_filteredEmployees.assignAll(
|
|
employees.where((e) {
|
|
return e.name.toLowerCase().contains(lowerQuery) ||
|
|
e.email.toLowerCase().contains(lowerQuery) ||
|
|
e.phoneNumber.toLowerCase().contains(lowerQuery) ||
|
|
e.jobRole.toLowerCase().contains(lowerQuery);
|
|
}),
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
appBar: PreferredSize(
|
|
preferredSize: const Size.fromHeight(72),
|
|
child: AppBar(
|
|
backgroundColor: const Color(0xFFF5F5F5),
|
|
elevation: 0.5,
|
|
automaticallyImplyLeading: false,
|
|
titleSpacing: 0,
|
|
title: Padding(
|
|
padding: MySpacing.xy(16, 0),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
IconButton(
|
|
icon: const Icon(Icons.arrow_back_ios_new,
|
|
color: Colors.black, size: 20),
|
|
onPressed: () => Get.offNamed('/dashboard'),
|
|
),
|
|
MySpacing.width(8),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
MyText.titleLarge(
|
|
'Employees',
|
|
fontWeight: 700,
|
|
color: Colors.black,
|
|
),
|
|
MySpacing.height(2),
|
|
GetBuilder<ProjectController>(
|
|
builder: (projectController) {
|
|
final projectName =
|
|
projectController.selectedProject?.name ??
|
|
'Select Project';
|
|
return Row(
|
|
children: [
|
|
const Icon(Icons.work_outline,
|
|
size: 14, color: Colors.grey),
|
|
MySpacing.width(4),
|
|
Expanded(
|
|
child: MyText.bodySmall(
|
|
projectName,
|
|
fontWeight: 600,
|
|
overflow: TextOverflow.ellipsis,
|
|
color: Colors.grey[700],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
floatingActionButton: InkWell(
|
|
onTap: () async {
|
|
final result = await showModalBottomSheet<bool>(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
|
),
|
|
backgroundColor: Colors.transparent,
|
|
builder: (context) => AddEmployeeBottomSheet(),
|
|
);
|
|
|
|
if (result == true) {
|
|
await _refreshEmployees();
|
|
}
|
|
},
|
|
borderRadius: BorderRadius.circular(28),
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
decoration: BoxDecoration(
|
|
color: Colors.red,
|
|
borderRadius: BorderRadius.circular(28),
|
|
boxShadow: const [
|
|
BoxShadow(
|
|
color: Colors.black26,
|
|
blurRadius: 6,
|
|
offset: Offset(0, 3),
|
|
),
|
|
],
|
|
),
|
|
child: const Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(Icons.add, color: Colors.white),
|
|
SizedBox(width: 8),
|
|
Text('Add New Employee', style: TextStyle(color: Colors.white)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
body: SafeArea(
|
|
child: GetBuilder<EmployeesScreenController>(
|
|
init: employeeScreenController,
|
|
tag: 'employee_screen_controller',
|
|
builder: (controller) {
|
|
_filterEmployees(_searchController.text);
|
|
return SingleChildScrollView(
|
|
padding: const EdgeInsets.only(bottom: 40),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
MySpacing.height(flexSpacing),
|
|
|
|
// Search Bar + Actions Row
|
|
Padding(
|
|
padding: MySpacing.x(flexSpacing),
|
|
child: Row(
|
|
children: [
|
|
// Search Field
|
|
Expanded(
|
|
child: SizedBox(
|
|
height: 36,
|
|
child: TextField(
|
|
controller: _searchController,
|
|
style: const TextStyle(fontSize: 13, height: 1.2),
|
|
decoration: InputDecoration(
|
|
isDense: true,
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
horizontal: 8, vertical: 8),
|
|
prefixIcon: const Icon(Icons.search,
|
|
size: 18, color: Colors.grey),
|
|
prefixIconConstraints: const BoxConstraints(
|
|
minWidth: 32,
|
|
minHeight: 32,
|
|
),
|
|
hintText: 'Search contacts...',
|
|
hintStyle: const TextStyle(
|
|
fontSize: 13, color: Colors.grey),
|
|
filled: true,
|
|
fillColor: Colors.white,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
borderSide: BorderSide(
|
|
color: Colors.grey.shade300, width: 1),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
borderSide: BorderSide(
|
|
color: Colors.grey.shade300, width: 1),
|
|
),
|
|
suffixIcon: _searchController.text.isNotEmpty
|
|
? GestureDetector(
|
|
onTap: () {
|
|
_searchController.clear();
|
|
_filterEmployees('');
|
|
setState(() {});
|
|
},
|
|
child: const Icon(Icons.close,
|
|
size: 18, color: Colors.grey),
|
|
)
|
|
: null,
|
|
),
|
|
onChanged: (value) => setState(() {}),
|
|
),
|
|
),
|
|
),
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
// Refresh Button
|
|
Tooltip(
|
|
message: 'Refresh Data',
|
|
child: InkWell(
|
|
borderRadius: BorderRadius.circular(24),
|
|
onTap: _refreshEmployees,
|
|
child: const Padding(
|
|
padding: EdgeInsets.all(10),
|
|
child: Icon(Icons.refresh,
|
|
color: Colors.green, size: 28),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 4),
|
|
|
|
// Three-dot Menu
|
|
PopupMenuButton<String>(
|
|
icon: Stack(
|
|
clipBehavior: Clip.none,
|
|
children: [
|
|
const Icon(Icons.tune, color: Colors.black),
|
|
Obx(() {
|
|
return employeeScreenController
|
|
.isAllEmployeeSelected.value
|
|
? Positioned(
|
|
right: -1,
|
|
top: -1,
|
|
child: Container(
|
|
width: 10,
|
|
height: 10,
|
|
decoration: const BoxDecoration(
|
|
color: Colors.red,
|
|
shape: BoxShape.circle,
|
|
),
|
|
),
|
|
)
|
|
: const SizedBox.shrink();
|
|
}),
|
|
],
|
|
),
|
|
onSelected: (value) async {
|
|
if (value == 'all_employees') {
|
|
employeeScreenController
|
|
.isAllEmployeeSelected.value =
|
|
!employeeScreenController
|
|
.isAllEmployeeSelected.value;
|
|
|
|
if (employeeScreenController
|
|
.isAllEmployeeSelected.value) {
|
|
employeeScreenController.selectedProjectId =
|
|
null;
|
|
await employeeScreenController
|
|
.fetchAllEmployees();
|
|
} else {
|
|
final selectedProjectId =
|
|
Get.find<ProjectController>()
|
|
.selectedProject
|
|
?.id;
|
|
if (selectedProjectId != null) {
|
|
employeeScreenController.selectedProjectId =
|
|
selectedProjectId;
|
|
await employeeScreenController
|
|
.fetchEmployeesByProject(
|
|
selectedProjectId);
|
|
} else {
|
|
employeeScreenController.clearEmployees();
|
|
}
|
|
}
|
|
_filterEmployees(_searchController.text);
|
|
employeeScreenController
|
|
.update(['employee_screen_controller']);
|
|
}
|
|
},
|
|
itemBuilder: (context) => [
|
|
PopupMenuItem<String>(
|
|
value: 'all_employees',
|
|
child: Obx(
|
|
() => Row(
|
|
children: [
|
|
Checkbox(
|
|
value: employeeScreenController
|
|
.isAllEmployeeSelected.value,
|
|
onChanged: (bool? value) {
|
|
Navigator.pop(context, 'all_employees');
|
|
},
|
|
checkColor: Colors.white,
|
|
activeColor: Colors.red,
|
|
side: const BorderSide(
|
|
color: Colors.black,
|
|
width: 1.5,
|
|
),
|
|
fillColor:
|
|
MaterialStateProperty.resolveWith(
|
|
(states) {
|
|
if (states
|
|
.contains(MaterialState.selected)) {
|
|
return Colors.red;
|
|
}
|
|
return Colors.white;
|
|
}),
|
|
),
|
|
const Text('All Employees'),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
MySpacing.height(flexSpacing),
|
|
|
|
// Employee List
|
|
Padding(
|
|
padding: MySpacing.x(flexSpacing),
|
|
child: dailyProgressReportTab(),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget dailyProgressReportTab() {
|
|
return Obx(() {
|
|
final isLoading = employeeScreenController.isLoading.value;
|
|
final employees = _filteredEmployees;
|
|
|
|
if (isLoading) {
|
|
return ListView.separated(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
itemCount: 10,
|
|
separatorBuilder: (_, __) => MySpacing.height(12),
|
|
itemBuilder: (_, __) => SkeletonLoaders.employeeSkeletonCard(),
|
|
);
|
|
}
|
|
|
|
if (employees.isEmpty) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(top: 50),
|
|
child: Center(
|
|
child: MyText.bodySmall(
|
|
"No Employees Found",
|
|
fontWeight: 600,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
return ListView.separated(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
padding: MySpacing.only(bottom: 80),
|
|
itemCount: employees.length,
|
|
separatorBuilder: (_, __) => MySpacing.height(12),
|
|
itemBuilder: (context, index) {
|
|
final employee = employees[index];
|
|
final nameParts = employee.name.trim().split(" ");
|
|
final firstName = nameParts.first;
|
|
final lastName = nameParts.length > 1 ? nameParts.last : "";
|
|
|
|
return InkWell(
|
|
onTap: () {
|
|
Get.to(() => EmployeeDetailPage(employeeId: employee.id));
|
|
},
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 0),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Avatar(firstName: firstName, lastName: lastName, size: 35),
|
|
MySpacing.width(12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
MyText.titleSmall(employee.name,
|
|
fontWeight: 600, overflow: TextOverflow.ellipsis),
|
|
if (employee.jobRole.isNotEmpty) ...[
|
|
MyText.bodySmall(employee.jobRole,
|
|
color: Colors.grey[700],
|
|
overflow: TextOverflow.ellipsis),
|
|
],
|
|
MySpacing.height(8),
|
|
if (employee.email.isNotEmpty &&
|
|
employee.email != '-') ...[
|
|
GestureDetector(
|
|
onTap: () =>
|
|
LauncherUtils.launchEmail(employee.email),
|
|
onLongPress: () => LauncherUtils.copyToClipboard(
|
|
employee.email,
|
|
typeLabel: 'Email'),
|
|
child: Row(
|
|
children: [
|
|
const Icon(Icons.email_outlined,
|
|
size: 16, color: Colors.indigo),
|
|
MySpacing.width(4),
|
|
ConstrainedBox(
|
|
constraints:
|
|
const BoxConstraints(maxWidth: 180),
|
|
child: MyText.labelSmall(
|
|
employee.email,
|
|
overflow: TextOverflow.ellipsis,
|
|
color: Colors.indigo,
|
|
decoration: TextDecoration.underline,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
MySpacing.height(6),
|
|
],
|
|
if (employee.phoneNumber.isNotEmpty) ...[
|
|
GestureDetector(
|
|
onTap: () =>
|
|
LauncherUtils.launchPhone(employee.phoneNumber),
|
|
onLongPress: () => LauncherUtils.copyToClipboard(
|
|
employee.phoneNumber,
|
|
typeLabel: 'Phone'),
|
|
child: Row(
|
|
children: [
|
|
const Icon(Icons.phone_outlined,
|
|
size: 16, color: Colors.indigo),
|
|
MySpacing.width(4),
|
|
MyText.labelSmall(
|
|
employee.phoneNumber,
|
|
color: Colors.indigo,
|
|
decoration: TextDecoration.underline,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
Column(
|
|
children: const [
|
|
Icon(Icons.arrow_forward_ios,
|
|
color: Colors.grey, size: 16),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
});
|
|
}
|
|
}
|