Refactor Expense Filter Bottom Sheet for improved readability and maintainability
- Extracted widget builders for Project, Expense Status, Date Range, Paid By, and Created By filters into separate methods. - Simplified date selection logic by creating a reusable _selectDate method. - Centralized input decoration for text fields. - Updated Expense Screen to use local state for search query and history view toggle. - Enhanced filtering logic for expenses based on search query and date. - Improved UI elements in Daily Progress Report and Daily Task Planning screens, including padding and border radius adjustments.
This commit is contained in:
parent
6d29d444fa
commit
f5eed0a0b9
@ -29,6 +29,12 @@ class ExpenseController extends GetxController {
|
|||||||
final RxList<EmployeeModel> selectedPaidByEmployees = <EmployeeModel>[].obs;
|
final RxList<EmployeeModel> selectedPaidByEmployees = <EmployeeModel>[].obs;
|
||||||
final RxList<EmployeeModel> selectedCreatedByEmployees =
|
final RxList<EmployeeModel> selectedCreatedByEmployees =
|
||||||
<EmployeeModel>[].obs;
|
<EmployeeModel>[].obs;
|
||||||
|
final RxString selectedDateType = 'Transaction Date'.obs;
|
||||||
|
|
||||||
|
final List<String> dateTypes = [
|
||||||
|
'Transaction Date',
|
||||||
|
'Created At',
|
||||||
|
];
|
||||||
|
|
||||||
int _pageSize = 20;
|
int _pageSize = 20;
|
||||||
int _pageNumber = 1;
|
int _pageNumber = 1;
|
||||||
@ -85,6 +91,7 @@ class ExpenseController extends GetxController {
|
|||||||
paidByIds ?? selectedPaidByEmployees.map((e) => e.id).toList(),
|
paidByIds ?? selectedPaidByEmployees.map((e) => e.id).toList(),
|
||||||
"startDate": (startDate ?? this.startDate.value)?.toIso8601String(),
|
"startDate": (startDate ?? this.startDate.value)?.toIso8601String(),
|
||||||
"endDate": (endDate ?? this.endDate.value)?.toIso8601String(),
|
"endDate": (endDate ?? this.endDate.value)?.toIso8601String(),
|
||||||
|
"isTransactionDate": selectedDateType.value == 'Transaction Date',
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -17,6 +17,7 @@ class DailyTaskPlaningController extends GetxController {
|
|||||||
|
|
||||||
MyFormValidator basicValidator = MyFormValidator();
|
MyFormValidator basicValidator = MyFormValidator();
|
||||||
List<Map<String, dynamic>> roles = [];
|
List<Map<String, dynamic>> roles = [];
|
||||||
|
RxBool isAssigningTask = false.obs;
|
||||||
|
|
||||||
RxnString selectedRoleId = RxnString();
|
RxnString selectedRoleId = RxnString();
|
||||||
RxBool isLoading = false.obs;
|
RxBool isLoading = false.obs;
|
||||||
@ -46,16 +47,21 @@ class DailyTaskPlaningController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateSelectedEmployees() {
|
void updateSelectedEmployees() {
|
||||||
final selected = employees
|
final selected =
|
||||||
.where((e) => uploadingStates[e.id]?.value == true)
|
employees.where((e) => uploadingStates[e.id]?.value == true).toList();
|
||||||
.toList();
|
|
||||||
selectedEmployees.value = selected;
|
selectedEmployees.value = selected;
|
||||||
logSafe("Updated selected employees", level: LogLevel.debug, );
|
logSafe(
|
||||||
|
"Updated selected employees",
|
||||||
|
level: LogLevel.debug,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onRoleSelected(String? roleId) {
|
void onRoleSelected(String? roleId) {
|
||||||
selectedRoleId.value = roleId;
|
selectedRoleId.value = roleId;
|
||||||
logSafe("Role selected", level: LogLevel.info, );
|
logSafe(
|
||||||
|
"Role selected",
|
||||||
|
level: LogLevel.info,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> fetchRoles() async {
|
Future<void> fetchRoles() async {
|
||||||
@ -77,6 +83,7 @@ class DailyTaskPlaningController extends GetxController {
|
|||||||
required List<String> taskTeam,
|
required List<String> taskTeam,
|
||||||
DateTime? assignmentDate,
|
DateTime? assignmentDate,
|
||||||
}) async {
|
}) async {
|
||||||
|
isAssigningTask.value = true;
|
||||||
logSafe("Starting assign task...", level: LogLevel.info);
|
logSafe("Starting assign task...", level: LogLevel.info);
|
||||||
|
|
||||||
final response = await ApiService.assignDailyTask(
|
final response = await ApiService.assignDailyTask(
|
||||||
@ -87,6 +94,8 @@ class DailyTaskPlaningController extends GetxController {
|
|||||||
assignmentDate: assignmentDate,
|
assignmentDate: assignmentDate,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
isAssigningTask.value = false;
|
||||||
|
|
||||||
if (response == true) {
|
if (response == true) {
|
||||||
logSafe("Task assigned successfully", level: LogLevel.info);
|
logSafe("Task assigned successfully", level: LogLevel.info);
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
@ -111,15 +120,18 @@ class DailyTaskPlaningController extends GetxController {
|
|||||||
try {
|
try {
|
||||||
final response = await ApiService.getProjects();
|
final response = await ApiService.getProjects();
|
||||||
if (response?.isEmpty ?? true) {
|
if (response?.isEmpty ?? true) {
|
||||||
logSafe("No project data found or API call failed", level: LogLevel.warning);
|
logSafe("No project data found or API call failed",
|
||||||
|
level: LogLevel.warning);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
projects = response!.map((json) => ProjectModel.fromJson(json)).toList();
|
projects = response!.map((json) => ProjectModel.fromJson(json)).toList();
|
||||||
logSafe("Projects fetched: ${projects.length} projects loaded", level: LogLevel.info);
|
logSafe("Projects fetched: ${projects.length} projects loaded",
|
||||||
|
level: LogLevel.info);
|
||||||
update();
|
update();
|
||||||
} catch (e, stack) {
|
} catch (e, stack) {
|
||||||
logSafe("Error fetching projects", level: LogLevel.error, error: e, stackTrace: stack);
|
logSafe("Error fetching projects",
|
||||||
|
level: LogLevel.error, error: e, stackTrace: stack);
|
||||||
} finally {
|
} finally {
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
}
|
}
|
||||||
@ -137,12 +149,16 @@ class DailyTaskPlaningController extends GetxController {
|
|||||||
final data = response?['data'];
|
final data = response?['data'];
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
dailyTasks = [TaskPlanningDetailsModel.fromJson(data)];
|
dailyTasks = [TaskPlanningDetailsModel.fromJson(data)];
|
||||||
logSafe("Daily task Planning Details fetched", level: LogLevel.info, );
|
logSafe(
|
||||||
|
"Daily task Planning Details fetched",
|
||||||
|
level: LogLevel.info,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
logSafe("Data field is null", level: LogLevel.warning);
|
logSafe("Data field is null", level: LogLevel.warning);
|
||||||
}
|
}
|
||||||
} catch (e, stack) {
|
} catch (e, stack) {
|
||||||
logSafe("Error fetching daily task data", level: LogLevel.error, error: e, stackTrace: stack);
|
logSafe("Error fetching daily task data",
|
||||||
|
level: LogLevel.error, error: e, stackTrace: stack);
|
||||||
} finally {
|
} finally {
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
update();
|
update();
|
||||||
@ -151,7 +167,8 @@ class DailyTaskPlaningController extends GetxController {
|
|||||||
|
|
||||||
Future<void> fetchEmployeesByProject(String? projectId) async {
|
Future<void> fetchEmployeesByProject(String? projectId) async {
|
||||||
if (projectId == null || projectId.isEmpty) {
|
if (projectId == null || projectId.isEmpty) {
|
||||||
logSafe("Project ID is required but was null or empty", level: LogLevel.error);
|
logSafe("Project ID is required but was null or empty",
|
||||||
|
level: LogLevel.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,19 +176,29 @@ class DailyTaskPlaningController extends GetxController {
|
|||||||
try {
|
try {
|
||||||
final response = await ApiService.getAllEmployeesByProject(projectId);
|
final response = await ApiService.getAllEmployeesByProject(projectId);
|
||||||
if (response != null && response.isNotEmpty) {
|
if (response != null && response.isNotEmpty) {
|
||||||
employees = response.map((json) => EmployeeModel.fromJson(json)).toList();
|
employees =
|
||||||
|
response.map((json) => EmployeeModel.fromJson(json)).toList();
|
||||||
for (var emp in employees) {
|
for (var emp in employees) {
|
||||||
uploadingStates[emp.id] = false.obs;
|
uploadingStates[emp.id] = false.obs;
|
||||||
}
|
}
|
||||||
logSafe("Employees fetched: ${employees.length} for project $projectId",
|
logSafe(
|
||||||
level: LogLevel.info, );
|
"Employees fetched: ${employees.length} for project $projectId",
|
||||||
|
level: LogLevel.info,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
employees = [];
|
employees = [];
|
||||||
logSafe("No employees found for project $projectId", level: LogLevel.warning, );
|
logSafe(
|
||||||
|
"No employees found for project $projectId",
|
||||||
|
level: LogLevel.warning,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (e, stack) {
|
} catch (e, stack) {
|
||||||
logSafe("Error fetching employees for project $projectId",
|
logSafe(
|
||||||
level: LogLevel.error, error: e, stackTrace: stack, );
|
"Error fetching employees for project $projectId",
|
||||||
|
level: LogLevel.error,
|
||||||
|
error: e,
|
||||||
|
stackTrace: stack,
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
update();
|
update();
|
||||||
|
@ -11,7 +11,8 @@ class BaseBottomSheet extends StatelessWidget {
|
|||||||
final String submitText;
|
final String submitText;
|
||||||
final Color submitColor;
|
final Color submitColor;
|
||||||
final IconData submitIcon;
|
final IconData submitIcon;
|
||||||
final bool showButtons;
|
final bool showButtons;
|
||||||
|
final Widget? bottomContent;
|
||||||
|
|
||||||
const BaseBottomSheet({
|
const BaseBottomSheet({
|
||||||
super.key,
|
super.key,
|
||||||
@ -23,7 +24,8 @@ class BaseBottomSheet extends StatelessWidget {
|
|||||||
this.submitText = 'Submit',
|
this.submitText = 'Submit',
|
||||||
this.submitColor = Colors.indigo,
|
this.submitColor = Colors.indigo,
|
||||||
this.submitIcon = Icons.check_circle_outline,
|
this.submitIcon = Icons.check_circle_outline,
|
||||||
this.showButtons = true,
|
this.showButtons = true,
|
||||||
|
this.bottomContent,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -65,8 +67,11 @@ class BaseBottomSheet extends StatelessWidget {
|
|||||||
MyText.titleLarge(title, fontWeight: 700),
|
MyText.titleLarge(title, fontWeight: 700),
|
||||||
MySpacing.height(12),
|
MySpacing.height(12),
|
||||||
child,
|
child,
|
||||||
MySpacing.height(24),
|
|
||||||
if (showButtons)
|
MySpacing.height(12),
|
||||||
|
|
||||||
|
// 👇 Buttons (if enabled)
|
||||||
|
if (showButtons) ...[
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
@ -108,6 +113,12 @@ class BaseBottomSheet extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
// 👇 Optional Bottom Content
|
||||||
|
if (bottomContent != null) ...[
|
||||||
|
MySpacing.height(12),
|
||||||
|
bottomContent!,
|
||||||
|
],
|
||||||
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:marco/controller/task_planing/daily_task_planing_controller.dart';
|
import 'package:marco/controller/task_planing/daily_task_planing_controller.dart';
|
||||||
import 'package:marco/helpers/widgets/my_text.dart';
|
|
||||||
import 'package:marco/helpers/widgets/my_spacing.dart';
|
|
||||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
|
||||||
import 'package:marco/controller/project_controller.dart';
|
import 'package:marco/controller/project_controller.dart';
|
||||||
|
import 'package:marco/helpers/widgets/my_spacing.dart';
|
||||||
|
import 'package:marco/helpers/widgets/my_text.dart';
|
||||||
|
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||||
|
import 'package:marco/helpers/utils/base_bottom_sheet.dart';
|
||||||
|
|
||||||
class AssignTaskBottomSheet extends StatefulWidget {
|
class AssignTaskBottomSheet extends StatefulWidget {
|
||||||
final String workLocation;
|
final String workLocation;
|
||||||
@ -37,17 +38,9 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
final ProjectController projectController = Get.find();
|
final ProjectController projectController = Get.find();
|
||||||
final TextEditingController targetController = TextEditingController();
|
final TextEditingController targetController = TextEditingController();
|
||||||
final TextEditingController descriptionController = TextEditingController();
|
final TextEditingController descriptionController = TextEditingController();
|
||||||
String? selectedProjectId;
|
|
||||||
|
|
||||||
final ScrollController _employeeListScrollController = ScrollController();
|
final ScrollController _employeeListScrollController = ScrollController();
|
||||||
|
|
||||||
@override
|
String? selectedProjectId;
|
||||||
void dispose() {
|
|
||||||
_employeeListScrollController.dispose();
|
|
||||||
targetController.dispose();
|
|
||||||
descriptionController.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -61,180 +54,105 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_employeeListScrollController.dispose();
|
||||||
|
targetController.dispose();
|
||||||
|
descriptionController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SafeArea(
|
return Obx(() => BaseBottomSheet(
|
||||||
child: Container(
|
title: "Assign Task",
|
||||||
padding: MediaQuery.of(context).viewInsets.add(MySpacing.all(16)),
|
child: _buildAssignTaskForm(),
|
||||||
decoration: const BoxDecoration(
|
onCancel: () => Get.back(),
|
||||||
color: Colors.white,
|
onSubmit: _onAssignTaskPressed,
|
||||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
isSubmitting: controller.isAssigningTask.value,
|
||||||
),
|
submitText: "Assign Task",
|
||||||
child: SingleChildScrollView(
|
submitIcon: Icons.check_circle_outline,
|
||||||
child: Column(
|
submitColor: Colors.indigo,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildAssignTaskForm() {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
_infoRow(Icons.location_on, "Work Location",
|
||||||
|
"${widget.buildingName} > ${widget.floorName} > ${widget.workAreaName} > ${widget.activityName}"),
|
||||||
|
Divider(),
|
||||||
|
_infoRow(Icons.pending_actions, "Pending Task of Activity",
|
||||||
|
"${widget.pendingTask}"),
|
||||||
|
Divider(),
|
||||||
|
GestureDetector(
|
||||||
|
onTap: _onRoleMenuPressed,
|
||||||
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Row(
|
MyText.titleMedium("Select Team :", fontWeight: 600),
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
const SizedBox(width: 4),
|
||||||
children: [
|
const Icon(Icons.tune, color: Color.fromARGB(255, 95, 132, 255)),
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.assignment, color: Colors.black54),
|
|
||||||
SizedBox(width: 8),
|
|
||||||
MyText.titleMedium("Assign Task",
|
|
||||||
fontSize: 18, fontWeight: 600),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.close),
|
|
||||||
onPressed: () => Get.back(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Divider(),
|
|
||||||
_infoRow(Icons.location_on, "Work Location",
|
|
||||||
"${widget.buildingName} > ${widget.floorName} > ${widget.workAreaName} > ${widget.activityName}"),
|
|
||||||
Divider(),
|
|
||||||
_infoRow(Icons.pending_actions, "Pending Task of Activity",
|
|
||||||
"${widget.pendingTask}"),
|
|
||||||
Divider(),
|
|
||||||
GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
final RenderBox overlay = Overlay.of(context)
|
|
||||||
.context
|
|
||||||
.findRenderObject() as RenderBox;
|
|
||||||
final Size screenSize = overlay.size;
|
|
||||||
|
|
||||||
showMenu(
|
|
||||||
context: context,
|
|
||||||
position: RelativeRect.fromLTRB(
|
|
||||||
screenSize.width / 2 - 100,
|
|
||||||
screenSize.height / 2 - 20,
|
|
||||||
screenSize.width / 2 - 100,
|
|
||||||
screenSize.height / 2 - 20,
|
|
||||||
),
|
|
||||||
items: [
|
|
||||||
const PopupMenuItem(
|
|
||||||
value: 'all',
|
|
||||||
child: Text("All Roles"),
|
|
||||||
),
|
|
||||||
...controller.roles.map((role) {
|
|
||||||
return PopupMenuItem(
|
|
||||||
value: role['id'].toString(),
|
|
||||||
child: Text(role['name'] ?? 'Unknown Role'),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
).then((value) {
|
|
||||||
if (value != null) {
|
|
||||||
controller.onRoleSelected(value == 'all' ? null : value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
MyText.titleMedium("Select Team :", fontWeight: 600),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Icon(Icons.tune,
|
|
||||||
color: const Color.fromARGB(255, 95, 132, 255)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
MySpacing.height(8),
|
|
||||||
Container(
|
|
||||||
constraints: BoxConstraints(maxHeight: 150),
|
|
||||||
child: _buildEmployeeList(),
|
|
||||||
),
|
|
||||||
MySpacing.height(8),
|
|
||||||
Obx(() {
|
|
||||||
if (controller.selectedEmployees.isEmpty) return Container();
|
|
||||||
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
||||||
child: Wrap(
|
|
||||||
spacing: 4,
|
|
||||||
runSpacing: 4,
|
|
||||||
children: controller.selectedEmployees.map((e) {
|
|
||||||
return Obx(() {
|
|
||||||
final isSelected =
|
|
||||||
controller.uploadingStates[e.id]?.value ?? false;
|
|
||||||
if (!isSelected) return Container();
|
|
||||||
|
|
||||||
return Chip(
|
|
||||||
label: Text(e.name,
|
|
||||||
style: const TextStyle(color: Colors.white)),
|
|
||||||
backgroundColor:
|
|
||||||
const Color.fromARGB(255, 95, 132, 255),
|
|
||||||
deleteIcon:
|
|
||||||
const Icon(Icons.close, color: Colors.white),
|
|
||||||
onDeleted: () {
|
|
||||||
controller.uploadingStates[e.id]?.value = false;
|
|
||||||
controller.updateSelectedEmployees();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}).toList(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
_buildTextField(
|
|
||||||
icon: Icons.track_changes,
|
|
||||||
label: "Target for Today :",
|
|
||||||
controller: targetController,
|
|
||||||
hintText: "Enter target",
|
|
||||||
keyboardType: TextInputType.number,
|
|
||||||
validatorType: "target",
|
|
||||||
),
|
|
||||||
MySpacing.height(24),
|
|
||||||
_buildTextField(
|
|
||||||
icon: Icons.description,
|
|
||||||
label: "Description :",
|
|
||||||
controller: descriptionController,
|
|
||||||
hintText: "Enter task description",
|
|
||||||
maxLines: 3,
|
|
||||||
validatorType: "description",
|
|
||||||
),
|
|
||||||
MySpacing.height(24),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
||||||
children: [
|
|
||||||
OutlinedButton.icon(
|
|
||||||
onPressed: () => Get.back(),
|
|
||||||
icon: const Icon(Icons.close, color: Colors.red),
|
|
||||||
label: MyText.bodyMedium("Cancel", color: Colors.red),
|
|
||||||
style: OutlinedButton.styleFrom(
|
|
||||||
side: const BorderSide(color: Colors.red),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 20, vertical: 14),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
ElevatedButton.icon(
|
|
||||||
onPressed: _onAssignTaskPressed,
|
|
||||||
icon: const Icon(Icons.check_circle_outline,
|
|
||||||
color: Colors.white),
|
|
||||||
label:
|
|
||||||
MyText.bodyMedium("Assign Task", color: Colors.white),
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.indigo,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 28, vertical: 14),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
MySpacing.height(8),
|
||||||
|
Container(
|
||||||
|
constraints: const BoxConstraints(maxHeight: 150),
|
||||||
|
child: _buildEmployeeList(),
|
||||||
|
),
|
||||||
|
MySpacing.height(8),
|
||||||
|
_buildSelectedEmployees(),
|
||||||
|
_buildTextField(
|
||||||
|
icon: Icons.track_changes,
|
||||||
|
label: "Target for Today :",
|
||||||
|
controller: targetController,
|
||||||
|
hintText: "Enter target",
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
validatorType: "target",
|
||||||
|
),
|
||||||
|
MySpacing.height(24),
|
||||||
|
_buildTextField(
|
||||||
|
icon: Icons.description,
|
||||||
|
label: "Description :",
|
||||||
|
controller: descriptionController,
|
||||||
|
hintText: "Enter task description",
|
||||||
|
maxLines: 3,
|
||||||
|
validatorType: "description",
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onRoleMenuPressed() {
|
||||||
|
final RenderBox overlay =
|
||||||
|
Overlay.of(context).context.findRenderObject() as RenderBox;
|
||||||
|
final Size screenSize = overlay.size;
|
||||||
|
|
||||||
|
showMenu(
|
||||||
|
context: context,
|
||||||
|
position: RelativeRect.fromLTRB(
|
||||||
|
screenSize.width / 2 - 100,
|
||||||
|
screenSize.height / 2 - 20,
|
||||||
|
screenSize.width / 2 - 100,
|
||||||
|
screenSize.height / 2 - 20,
|
||||||
|
),
|
||||||
|
items: [
|
||||||
|
const PopupMenuItem(value: 'all', child: Text("All Roles")),
|
||||||
|
...controller.roles.map((role) {
|
||||||
|
return PopupMenuItem(
|
||||||
|
value: role['id'].toString(),
|
||||||
|
child: Text(role['name'] ?? 'Unknown Role'),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
).then((value) {
|
||||||
|
if (value != null) {
|
||||||
|
controller.onRoleSelected(value == 'all' ? null : value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildEmployeeList() {
|
Widget _buildEmployeeList() {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
if (controller.isLoading.value) {
|
if (controller.isLoading.value) {
|
||||||
@ -255,49 +173,43 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
return Scrollbar(
|
return Scrollbar(
|
||||||
controller: _employeeListScrollController,
|
controller: _employeeListScrollController,
|
||||||
thumbVisibility: true,
|
thumbVisibility: true,
|
||||||
interactive: true,
|
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
controller: _employeeListScrollController,
|
controller: _employeeListScrollController,
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
|
||||||
itemCount: filteredEmployees.length,
|
itemCount: filteredEmployees.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final employee = filteredEmployees[index];
|
final employee = filteredEmployees[index];
|
||||||
final rxBool = controller.uploadingStates[employee.id];
|
final rxBool = controller.uploadingStates[employee.id];
|
||||||
|
|
||||||
return Obx(() => Padding(
|
return Obx(() => Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 0),
|
padding: const EdgeInsets.symmetric(vertical: 2),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Theme(
|
Checkbox(
|
||||||
data: Theme.of(context)
|
shape: RoundedRectangleBorder(
|
||||||
.copyWith(unselectedWidgetColor: Colors.black),
|
borderRadius: BorderRadius.circular(4),
|
||||||
child: Checkbox(
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(4),
|
|
||||||
side: const BorderSide(color: Colors.black),
|
|
||||||
),
|
|
||||||
value: rxBool?.value ?? false,
|
|
||||||
onChanged: (bool? selected) {
|
|
||||||
if (rxBool != null) {
|
|
||||||
rxBool.value = selected ?? false;
|
|
||||||
controller.updateSelectedEmployees();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
fillColor:
|
|
||||||
WidgetStateProperty.resolveWith<Color>((states) {
|
|
||||||
if (states.contains(WidgetState.selected)) {
|
|
||||||
return const Color.fromARGB(255, 95, 132, 255);
|
|
||||||
}
|
|
||||||
return Colors.transparent;
|
|
||||||
}),
|
|
||||||
checkColor: Colors.white,
|
|
||||||
side: const BorderSide(color: Colors.black),
|
|
||||||
),
|
),
|
||||||
|
value: rxBool?.value ?? false,
|
||||||
|
onChanged: (bool? selected) {
|
||||||
|
if (rxBool != null) {
|
||||||
|
rxBool.value = selected ?? false;
|
||||||
|
controller.updateSelectedEmployees();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fillColor:
|
||||||
|
WidgetStateProperty.resolveWith<Color>((states) {
|
||||||
|
if (states.contains(WidgetState.selected)) {
|
||||||
|
return const Color.fromARGB(255, 95, 132, 255);
|
||||||
|
}
|
||||||
|
return Colors.transparent;
|
||||||
|
}),
|
||||||
|
checkColor: Colors.white,
|
||||||
|
side: const BorderSide(color: Colors.black),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(employee.name,
|
child: Text(employee.name,
|
||||||
style: TextStyle(fontSize: 14))),
|
style: const TextStyle(fontSize: 14))),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
@ -307,6 +219,38 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildSelectedEmployees() {
|
||||||
|
return Obx(() {
|
||||||
|
if (controller.selectedEmployees.isEmpty) return Container();
|
||||||
|
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||||
|
child: Wrap(
|
||||||
|
spacing: 4,
|
||||||
|
runSpacing: 4,
|
||||||
|
children: controller.selectedEmployees.map((e) {
|
||||||
|
return Obx(() {
|
||||||
|
final isSelected =
|
||||||
|
controller.uploadingStates[e.id]?.value ?? false;
|
||||||
|
if (!isSelected) return Container();
|
||||||
|
|
||||||
|
return Chip(
|
||||||
|
label:
|
||||||
|
Text(e.name, style: const TextStyle(color: Colors.white)),
|
||||||
|
backgroundColor: const Color.fromARGB(255, 95, 132, 255),
|
||||||
|
deleteIcon: const Icon(Icons.close, color: Colors.white),
|
||||||
|
onDeleted: () {
|
||||||
|
controller.uploadingStates[e.id]?.value = false;
|
||||||
|
controller.updateSelectedEmployees();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildTextField({
|
Widget _buildTextField({
|
||||||
required IconData icon,
|
required IconData icon,
|
||||||
required String label,
|
required String label,
|
||||||
@ -331,13 +275,12 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
controller: controller,
|
controller: controller,
|
||||||
keyboardType: keyboardType,
|
keyboardType: keyboardType,
|
||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
decoration: InputDecoration(
|
decoration: const InputDecoration(
|
||||||
hintText: hintText,
|
hintText: '',
|
||||||
border: const OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
validator: (value) => this
|
validator: (value) =>
|
||||||
.controller
|
this.controller.formFieldValidator(value, fieldType: validatorType),
|
||||||
.formFieldValidator(value, fieldType: validatorType),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -3,16 +3,14 @@ import 'package:get/get.dart';
|
|||||||
import 'package:marco/controller/task_planing/report_task_action_controller.dart';
|
import 'package:marco/controller/task_planing/report_task_action_controller.dart';
|
||||||
import 'package:marco/helpers/theme/app_theme.dart';
|
import 'package:marco/helpers/theme/app_theme.dart';
|
||||||
import 'package:marco/helpers/utils/mixins/ui_mixin.dart';
|
import 'package:marco/helpers/utils/mixins/ui_mixin.dart';
|
||||||
import 'package:marco/helpers/widgets/my_button.dart';
|
|
||||||
import 'package:marco/helpers/widgets/my_spacing.dart';
|
import 'package:marco/helpers/widgets/my_spacing.dart';
|
||||||
import 'package:marco/helpers/widgets/my_text.dart';
|
import 'package:marco/helpers/widgets/my_text.dart';
|
||||||
import 'package:marco/helpers/widgets/my_text_style.dart';
|
import 'package:marco/helpers/widgets/my_text_style.dart';
|
||||||
import 'package:marco/helpers/widgets/avatar.dart';
|
import 'package:marco/helpers/widgets/avatar.dart';
|
||||||
import 'package:marco/helpers/widgets/my_team_model_sheet.dart';
|
import 'package:marco/helpers/widgets/my_team_model_sheet.dart';
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
import 'package:marco/helpers/widgets/image_viewer_dialog.dart';
|
import 'package:marco/helpers/widgets/image_viewer_dialog.dart';
|
||||||
import 'package:marco/model/dailyTaskPlaning/create_task_botom_sheet.dart';
|
import 'package:marco/model/dailyTaskPlaning/create_task_botom_sheet.dart';
|
||||||
import 'dart:io';
|
import 'package:marco/model/dailyTaskPlaning/report_action_widgets.dart';
|
||||||
|
|
||||||
class ReportActionBottomSheet extends StatefulWidget {
|
class ReportActionBottomSheet extends StatefulWidget {
|
||||||
final Map<String, dynamic> taskData;
|
final Map<String, dynamic> taskData;
|
||||||
@ -90,28 +88,6 @@ class _ReportActionBottomSheetState extends State<ReportActionBottomSheet>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
String timeAgo(String dateString) {
|
|
||||||
try {
|
|
||||||
DateTime date = DateTime.parse(dateString + "Z").toLocal();
|
|
||||||
final now = DateTime.now();
|
|
||||||
final difference = now.difference(date);
|
|
||||||
if (difference.inDays > 8) {
|
|
||||||
return DateFormat('dd-MM-yyyy').format(date);
|
|
||||||
} else if (difference.inDays >= 1) {
|
|
||||||
return '${difference.inDays} day${difference.inDays > 1 ? 's' : ''} ago';
|
|
||||||
} else if (difference.inHours >= 1) {
|
|
||||||
return '${difference.inHours} hr${difference.inHours > 1 ? 's' : ''} ago';
|
|
||||||
} else if (difference.inMinutes >= 1) {
|
|
||||||
return '${difference.inMinutes} min${difference.inMinutes > 1 ? 's' : ''} ago';
|
|
||||||
} else {
|
|
||||||
return 'just now';
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
print('Error parsing date: $e');
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
@ -523,7 +499,8 @@ class _ReportActionBottomSheetState extends State<ReportActionBottomSheet>
|
|||||||
final comments = List<Map<String, dynamic>>.from(
|
final comments = List<Map<String, dynamic>>.from(
|
||||||
widget.taskData['taskComments'] as List,
|
widget.taskData['taskComments'] as List,
|
||||||
);
|
);
|
||||||
return buildCommentList(comments, context);
|
return buildCommentList(
|
||||||
|
comments, context, timeAgo);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
@ -539,79 +516,6 @@ class _ReportActionBottomSheetState extends State<ReportActionBottomSheet>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildReportedImagesSection({
|
|
||||||
required List<String> imageUrls,
|
|
||||||
required BuildContext context,
|
|
||||||
String title = "Reported Images",
|
|
||||||
}) {
|
|
||||||
if (imageUrls.isEmpty) return const SizedBox();
|
|
||||||
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
MySpacing.height(8),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 0.0),
|
|
||||||
child: Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.image_outlined, size: 18, color: Colors.grey[700]),
|
|
||||||
MySpacing.width(8),
|
|
||||||
MyText.titleSmall(
|
|
||||||
title,
|
|
||||||
fontWeight: 600,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
MySpacing.height(8),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
||||||
child: SizedBox(
|
|
||||||
height: 70,
|
|
||||||
child: ListView.separated(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
itemCount: imageUrls.length,
|
|
||||||
separatorBuilder: (_, __) => const SizedBox(width: 12),
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final url = imageUrls[index];
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
barrierColor: Colors.black54,
|
|
||||||
builder: (_) => ImageViewerDialog(
|
|
||||||
imageSources: imageUrls,
|
|
||||||
initialIndex: index,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
child: Image.network(
|
|
||||||
url,
|
|
||||||
width: 70,
|
|
||||||
height: 70,
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
errorBuilder: (context, error, stackTrace) => Container(
|
|
||||||
width: 70,
|
|
||||||
height: 70,
|
|
||||||
color: Colors.grey.shade200,
|
|
||||||
child:
|
|
||||||
Icon(Icons.broken_image, color: Colors.grey[600]),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
MySpacing.height(16),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget buildTeamMembers() {
|
Widget buildTeamMembers() {
|
||||||
final teamMembersText =
|
final teamMembersText =
|
||||||
controller.basicValidator.getController('team_members')?.text ?? '';
|
controller.basicValidator.getController('team_members')?.text ?? '';
|
||||||
@ -676,360 +580,4 @@ class _ReportActionBottomSheetState extends State<ReportActionBottomSheet>
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildCommentActionButtons({
|
|
||||||
required VoidCallback onCancel,
|
|
||||||
required Future<void> Function() onSubmit,
|
|
||||||
required RxBool isLoading,
|
|
||||||
double? buttonHeight,
|
|
||||||
}) {
|
|
||||||
return Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: OutlinedButton.icon(
|
|
||||||
onPressed: onCancel,
|
|
||||||
icon: const Icon(Icons.close, color: Colors.red, size: 18),
|
|
||||||
label: MyText.bodyMedium("Cancel", color: Colors.red, fontWeight: 600),
|
|
||||||
style: OutlinedButton.styleFrom(
|
|
||||||
side: const BorderSide(color: Colors.red),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 16),
|
|
||||||
Expanded(
|
|
||||||
child: Obx(() {
|
|
||||||
return ElevatedButton.icon(
|
|
||||||
onPressed: isLoading.value ? null : () => onSubmit(),
|
|
||||||
icon: isLoading.value
|
|
||||||
? const SizedBox(
|
|
||||||
width: 16,
|
|
||||||
height: 16,
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
strokeWidth: 2,
|
|
||||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: const Icon(Icons.send, color: Colors.white, size: 18),
|
|
||||||
label: isLoading.value
|
|
||||||
? const SizedBox()
|
|
||||||
: MyText.bodyMedium("Submit", color: Colors.white, fontWeight: 600),
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.indigo,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget buildRow(String label, String? value, {IconData? icon}) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(bottom: 16),
|
|
||||||
child: Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
if (icon != null)
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(right: 8.0, top: 2),
|
|
||||||
child: Icon(icon, size: 18, color: Colors.grey[700]),
|
|
||||||
),
|
|
||||||
MyText.titleSmall(
|
|
||||||
"$label:",
|
|
||||||
fontWeight: 600,
|
|
||||||
),
|
|
||||||
MySpacing.width(12),
|
|
||||||
Expanded(
|
|
||||||
child: MyText.bodyMedium(value?.isNotEmpty == true ? value! : "-"),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget buildCommentList(
|
|
||||||
List<Map<String, dynamic>> comments, BuildContext context) {
|
|
||||||
comments.sort((a, b) {
|
|
||||||
final aDate = DateTime.tryParse(a['date'] ?? '') ??
|
|
||||||
DateTime.fromMillisecondsSinceEpoch(0);
|
|
||||||
final bDate = DateTime.tryParse(b['date'] ?? '') ??
|
|
||||||
DateTime.fromMillisecondsSinceEpoch(0);
|
|
||||||
return bDate.compareTo(aDate); // newest first
|
|
||||||
});
|
|
||||||
|
|
||||||
return SizedBox(
|
|
||||||
height: 300,
|
|
||||||
child: ListView.builder(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
||||||
itemCount: comments.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final comment = comments[index];
|
|
||||||
final commentText = comment['text'] ?? '-';
|
|
||||||
final commentedBy = comment['commentedBy'] ?? 'Unknown';
|
|
||||||
final relativeTime = timeAgo(comment['date'] ?? '');
|
|
||||||
final imageUrls = List<String>.from(comment['preSignedUrls'] ?? []);
|
|
||||||
|
|
||||||
return Container(
|
|
||||||
margin: const EdgeInsets.symmetric(vertical: 8),
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.grey.shade200,
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Avatar(
|
|
||||||
firstName: commentedBy.split(' ').first,
|
|
||||||
lastName: commentedBy.split(' ').length > 1
|
|
||||||
? commentedBy.split(' ').last
|
|
||||||
: '',
|
|
||||||
size: 32,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Expanded(
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
MyText.bodyMedium(
|
|
||||||
commentedBy,
|
|
||||||
fontWeight: 700,
|
|
||||||
color: Colors.black87,
|
|
||||||
),
|
|
||||||
MyText.bodySmall(
|
|
||||||
relativeTime,
|
|
||||||
fontSize: 12,
|
|
||||||
color: Colors.black54,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: MyText.bodyMedium(
|
|
||||||
commentText,
|
|
||||||
fontWeight: 500,
|
|
||||||
color: Colors.black87,
|
|
||||||
maxLines: null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
if (imageUrls.isNotEmpty) ...[
|
|
||||||
Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.attach_file_outlined,
|
|
||||||
size: 18, color: Colors.grey[700]),
|
|
||||||
MyText.bodyMedium(
|
|
||||||
'Attachments',
|
|
||||||
fontWeight: 600,
|
|
||||||
color: Colors.black87,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
SizedBox(
|
|
||||||
height: 60,
|
|
||||||
child: ListView.separated(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
itemCount: imageUrls.length,
|
|
||||||
itemBuilder: (context, imageIndex) {
|
|
||||||
final imageUrl = imageUrls[imageIndex];
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
barrierColor: Colors.black54,
|
|
||||||
builder: (_) => ImageViewerDialog(
|
|
||||||
imageSources: imageUrls,
|
|
||||||
initialIndex: imageIndex,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: Stack(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
width: 60,
|
|
||||||
height: 60,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
color: Colors.grey[100],
|
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Colors.black26,
|
|
||||||
blurRadius: 6,
|
|
||||||
offset: Offset(2, 2),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
child: ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
child: Image.network(
|
|
||||||
imageUrl,
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
errorBuilder:
|
|
||||||
(context, error, stackTrace) =>
|
|
||||||
Container(
|
|
||||||
color: Colors.grey[300],
|
|
||||||
child: Icon(Icons.broken_image,
|
|
||||||
color: Colors.grey[700]),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Positioned(
|
|
||||||
right: 4,
|
|
||||||
bottom: 4,
|
|
||||||
child: Icon(Icons.zoom_in,
|
|
||||||
color: Colors.white70, size: 16),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
separatorBuilder: (_, __) =>
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget buildImagePickerSection({
|
|
||||||
required List<File> images,
|
|
||||||
required VoidCallback onCameraTap,
|
|
||||||
required VoidCallback onUploadTap,
|
|
||||||
required void Function(int index) onRemoveImage,
|
|
||||||
required void Function(int initialIndex) onPreviewImage,
|
|
||||||
}) {
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
if (images.isEmpty)
|
|
||||||
Container(
|
|
||||||
height: 70,
|
|
||||||
width: double.infinity,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
border: Border.all(color: Colors.grey.shade300, width: 2),
|
|
||||||
color: Colors.grey.shade100,
|
|
||||||
),
|
|
||||||
child: Center(
|
|
||||||
child: Icon(Icons.photo_camera_outlined,
|
|
||||||
size: 48, color: Colors.grey.shade400),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
else
|
|
||||||
SizedBox(
|
|
||||||
height: 70,
|
|
||||||
child: ListView.separated(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
itemCount: images.length,
|
|
||||||
separatorBuilder: (_, __) => const SizedBox(width: 12),
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final file = images[index];
|
|
||||||
return Stack(
|
|
||||||
children: [
|
|
||||||
GestureDetector(
|
|
||||||
onTap: () => onPreviewImage(index),
|
|
||||||
child: ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
child: Image.file(
|
|
||||||
file,
|
|
||||||
height: 70,
|
|
||||||
width: 70,
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
top: 4,
|
|
||||||
right: 4,
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () => onRemoveImage(index),
|
|
||||||
child: Container(
|
|
||||||
decoration: const BoxDecoration(
|
|
||||||
color: Colors.black54,
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
),
|
|
||||||
child: const Icon(Icons.close,
|
|
||||||
size: 20, color: Colors.white),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
MySpacing.height(16),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: MyButton.outlined(
|
|
||||||
onPressed: onCameraTap,
|
|
||||||
padding: MySpacing.xy(12, 10),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.camera_alt,
|
|
||||||
size: 16, color: Colors.blueAccent),
|
|
||||||
MySpacing.width(6),
|
|
||||||
MyText.bodySmall('Capture', color: Colors.blueAccent),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
MySpacing.width(12),
|
|
||||||
Expanded(
|
|
||||||
child: MyButton.outlined(
|
|
||||||
onPressed: onUploadTap,
|
|
||||||
padding: MySpacing.xy(12, 10),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.upload_file,
|
|
||||||
size: 16, color: Colors.blueAccent),
|
|
||||||
MySpacing.width(6),
|
|
||||||
MyText.bodySmall('Upload', color: Colors.blueAccent),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
392
lib/model/dailyTaskPlaning/report_action_widgets.dart
Normal file
392
lib/model/dailyTaskPlaning/report_action_widgets.dart
Normal file
@ -0,0 +1,392 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:marco/helpers/widgets/my_button.dart';
|
||||||
|
import 'package:marco/helpers/widgets/my_spacing.dart';
|
||||||
|
import 'package:marco/helpers/widgets/my_text.dart';
|
||||||
|
import 'package:marco/helpers/widgets/image_viewer_dialog.dart';
|
||||||
|
import 'package:marco/helpers/widgets/avatar.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
|
/// Show labeled row with optional icon
|
||||||
|
Widget buildRow(String label, String? value, {IconData? icon}) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 16),
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
if (icon != null)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 8.0, top: 2),
|
||||||
|
child: Icon(icon, size: 18, color: Colors.grey[700]),
|
||||||
|
),
|
||||||
|
MyText.titleSmall("$label:", fontWeight: 600),
|
||||||
|
MySpacing.width(12),
|
||||||
|
Expanded(
|
||||||
|
child: MyText.bodyMedium(value?.isNotEmpty == true ? value! : "-"),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Show uploaded network images
|
||||||
|
Widget buildReportedImagesSection({
|
||||||
|
required List<String> imageUrls,
|
||||||
|
required BuildContext context,
|
||||||
|
String title = "Reported Images",
|
||||||
|
}) {
|
||||||
|
if (imageUrls.isEmpty) return const SizedBox();
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
MySpacing.height(8),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.image_outlined, size: 18, color: Colors.grey[700]),
|
||||||
|
MySpacing.width(8),
|
||||||
|
MyText.titleSmall(title, fontWeight: 600),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
MySpacing.height(8),
|
||||||
|
SizedBox(
|
||||||
|
height: 70,
|
||||||
|
child: ListView.separated(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
itemCount: imageUrls.length,
|
||||||
|
separatorBuilder: (_, __) => const SizedBox(width: 12),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final url = imageUrls[index];
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => ImageViewerDialog(
|
||||||
|
imageSources: imageUrls,
|
||||||
|
initialIndex: index,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
child: Image.network(
|
||||||
|
url,
|
||||||
|
width: 70,
|
||||||
|
height: 70,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
errorBuilder: (context, error, stackTrace) => Container(
|
||||||
|
width: 70,
|
||||||
|
height: 70,
|
||||||
|
color: Colors.grey.shade200,
|
||||||
|
child: Icon(Icons.broken_image, color: Colors.grey[600]),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
MySpacing.height(16),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Local image picker preview (with file images)
|
||||||
|
Widget buildImagePickerSection({
|
||||||
|
required List<File> images,
|
||||||
|
required VoidCallback onCameraTap,
|
||||||
|
required VoidCallback onUploadTap,
|
||||||
|
required void Function(int index) onRemoveImage,
|
||||||
|
required void Function(int initialIndex) onPreviewImage,
|
||||||
|
}) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
if (images.isEmpty)
|
||||||
|
Container(
|
||||||
|
height: 70,
|
||||||
|
width: double.infinity,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
border: Border.all(color: Colors.grey.shade300, width: 2),
|
||||||
|
color: Colors.grey.shade100,
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Icon(Icons.photo_camera_outlined,
|
||||||
|
size: 48, color: Colors.grey.shade400),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
SizedBox(
|
||||||
|
height: 70,
|
||||||
|
child: ListView.separated(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
itemCount: images.length,
|
||||||
|
separatorBuilder: (_, __) => const SizedBox(width: 12),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final file = images[index];
|
||||||
|
return Stack(
|
||||||
|
children: [
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () => onPreviewImage(index),
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
child: Image.file(
|
||||||
|
file,
|
||||||
|
height: 70,
|
||||||
|
width: 70,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
top: 4,
|
||||||
|
right: 4,
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () => onRemoveImage(index),
|
||||||
|
child: Container(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
color: Colors.black54,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
child: const Icon(Icons.close,
|
||||||
|
size: 20, color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
MySpacing.height(16),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: MyButton.outlined(
|
||||||
|
onPressed: onCameraTap,
|
||||||
|
padding: MySpacing.xy(12, 10),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.camera_alt,
|
||||||
|
size: 16, color: Colors.blueAccent),
|
||||||
|
MySpacing.width(6),
|
||||||
|
MyText.bodySmall('Capture', color: Colors.blueAccent),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
MySpacing.width(12),
|
||||||
|
Expanded(
|
||||||
|
child: MyButton.outlined(
|
||||||
|
onPressed: onUploadTap,
|
||||||
|
padding: MySpacing.xy(12, 10),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.upload_file,
|
||||||
|
size: 16, color: Colors.blueAccent),
|
||||||
|
MySpacing.width(6),
|
||||||
|
MyText.bodySmall('Upload', color: Colors.blueAccent),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Comment list widget
|
||||||
|
Widget buildCommentList(
|
||||||
|
List<Map<String, dynamic>> comments, BuildContext context, String Function(String) timeAgo) {
|
||||||
|
comments.sort((a, b) {
|
||||||
|
final aDate = DateTime.tryParse(a['date'] ?? '') ??
|
||||||
|
DateTime.fromMillisecondsSinceEpoch(0);
|
||||||
|
final bDate = DateTime.tryParse(b['date'] ?? '') ??
|
||||||
|
DateTime.fromMillisecondsSinceEpoch(0);
|
||||||
|
return bDate.compareTo(aDate); // newest first
|
||||||
|
});
|
||||||
|
|
||||||
|
return SizedBox(
|
||||||
|
height: 300,
|
||||||
|
child: ListView.builder(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||||
|
itemCount: comments.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final comment = comments[index];
|
||||||
|
final commentText = comment['text'] ?? '-';
|
||||||
|
final commentedBy = comment['commentedBy'] ?? 'Unknown';
|
||||||
|
final relativeTime = timeAgo(comment['date'] ?? '');
|
||||||
|
final imageUrls = List<String>.from(comment['preSignedUrls'] ?? []);
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
margin: const EdgeInsets.symmetric(vertical: 8),
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey.shade200,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Avatar(
|
||||||
|
firstName: commentedBy.split(' ').first,
|
||||||
|
lastName: commentedBy.split(' ').length > 1
|
||||||
|
? commentedBy.split(' ').last
|
||||||
|
: '',
|
||||||
|
size: 32,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
MyText.bodyMedium(commentedBy,
|
||||||
|
fontWeight: 700, color: Colors.black87),
|
||||||
|
MyText.bodySmall(
|
||||||
|
relativeTime,
|
||||||
|
fontSize: 12,
|
||||||
|
color: Colors.black54,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
MyText.bodyMedium(commentText,
|
||||||
|
fontWeight: 500, color: Colors.black87),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
if (imageUrls.isNotEmpty) ...[
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.attach_file_outlined,
|
||||||
|
size: 18, color: Colors.grey[700]),
|
||||||
|
MySpacing.width(8),
|
||||||
|
MyText.bodyMedium('Attachments',
|
||||||
|
fontWeight: 600, color: Colors.black87),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
SizedBox(
|
||||||
|
height: 60,
|
||||||
|
child: ListView.separated(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
itemCount: imageUrls.length,
|
||||||
|
itemBuilder: (context, imageIndex) {
|
||||||
|
final imageUrl = imageUrls[imageIndex];
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => ImageViewerDialog(
|
||||||
|
imageSources: imageUrls,
|
||||||
|
initialIndex: imageIndex,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
child: Image.network(
|
||||||
|
imageUrl,
|
||||||
|
width: 60,
|
||||||
|
height: 60,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
separatorBuilder: (_, __) => const SizedBox(width: 12),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cancel + Submit buttons
|
||||||
|
Widget buildCommentActionButtons({
|
||||||
|
required VoidCallback onCancel,
|
||||||
|
required Future<void> Function() onSubmit,
|
||||||
|
required RxBool isLoading,
|
||||||
|
}) {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: OutlinedButton.icon(
|
||||||
|
onPressed: onCancel,
|
||||||
|
icon: const Icon(Icons.close, color: Colors.red, size: 18),
|
||||||
|
label:
|
||||||
|
MyText.bodyMedium("Cancel", color: Colors.red, fontWeight: 600),
|
||||||
|
style: OutlinedButton.styleFrom(
|
||||||
|
side: const BorderSide(color: Colors.red),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
Expanded(
|
||||||
|
child: Obx(() {
|
||||||
|
return ElevatedButton.icon(
|
||||||
|
onPressed: isLoading.value ? null : () => onSubmit(),
|
||||||
|
icon: isLoading.value
|
||||||
|
? const SizedBox(
|
||||||
|
width: 16,
|
||||||
|
height: 16,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2,
|
||||||
|
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: const Icon(Icons.send, color: Colors.white, size: 18),
|
||||||
|
label: isLoading.value
|
||||||
|
? const SizedBox()
|
||||||
|
: MyText.bodyMedium("Submit",
|
||||||
|
color: Colors.white, fontWeight: 600),
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.indigo,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Converts a UTC timestamp to a relative time string
|
||||||
|
String timeAgo(String dateString) {
|
||||||
|
try {
|
||||||
|
DateTime date = DateTime.parse(dateString + "Z").toLocal();
|
||||||
|
final now = DateTime.now();
|
||||||
|
final difference = now.difference(date);
|
||||||
|
if (difference.inDays > 8) {
|
||||||
|
return "${date.day.toString().padLeft(2, '0')}-${date.month.toString().padLeft(2, '0')}-${date.year}";
|
||||||
|
} else if (difference.inDays >= 1) {
|
||||||
|
return '${difference.inDays} day${difference.inDays > 1 ? 's' : ''} ago';
|
||||||
|
} else if (difference.inHours >= 1) {
|
||||||
|
return '${difference.inHours} hr${difference.inHours > 1 ? 's' : ''} ago';
|
||||||
|
} else if (difference.inMinutes >= 1) {
|
||||||
|
return '${difference.inMinutes} min${difference.inMinutes > 1 ? 's' : ''} ago';
|
||||||
|
} else {
|
||||||
|
return 'just now';
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
@ -6,10 +6,12 @@ import 'package:marco/helpers/widgets/my_button.dart';
|
|||||||
import 'package:marco/helpers/widgets/my_spacing.dart';
|
import 'package:marco/helpers/widgets/my_spacing.dart';
|
||||||
import 'package:marco/helpers/widgets/my_text.dart';
|
import 'package:marco/helpers/widgets/my_text.dart';
|
||||||
import 'package:marco/helpers/widgets/my_text_style.dart';
|
import 'package:marco/helpers/widgets/my_text_style.dart';
|
||||||
|
import 'package:marco/helpers/utils/base_bottom_sheet.dart';
|
||||||
|
|
||||||
class ReportTaskBottomSheet extends StatefulWidget {
|
class ReportTaskBottomSheet extends StatefulWidget {
|
||||||
final Map<String, dynamic> taskData;
|
final Map<String, dynamic> taskData;
|
||||||
final VoidCallback? onReportSuccess;
|
final VoidCallback? onReportSuccess;
|
||||||
|
|
||||||
const ReportTaskBottomSheet({
|
const ReportTaskBottomSheet({
|
||||||
super.key,
|
super.key,
|
||||||
required this.taskData,
|
required this.taskData,
|
||||||
@ -27,464 +29,282 @@ class _ReportTaskBottomSheetState extends State<ReportTaskBottomSheet>
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
// Initialize the controller with a unique tag (optional)
|
controller = Get.put(
|
||||||
controller = Get.put(ReportTaskController(),
|
ReportTaskController(),
|
||||||
tag: widget.taskData['taskId'] ?? UniqueKey().toString());
|
tag: widget.taskData['taskId'] ?? UniqueKey().toString(),
|
||||||
|
);
|
||||||
|
_preFillFormFields();
|
||||||
|
}
|
||||||
|
|
||||||
final taskData = widget.taskData;
|
void _preFillFormFields() {
|
||||||
controller.basicValidator.getController('assigned_date')?.text =
|
final data = widget.taskData;
|
||||||
taskData['assignedOn'] ?? '';
|
final v = controller.basicValidator;
|
||||||
controller.basicValidator.getController('assigned_by')?.text =
|
|
||||||
taskData['assignedBy'] ?? '';
|
v.getController('assigned_date')?.text = data['assignedOn'] ?? '';
|
||||||
controller.basicValidator.getController('work_area')?.text =
|
v.getController('assigned_by')?.text = data['assignedBy'] ?? '';
|
||||||
taskData['location'] ?? '';
|
v.getController('work_area')?.text = data['location'] ?? '';
|
||||||
controller.basicValidator.getController('activity')?.text =
|
v.getController('activity')?.text = data['activity'] ?? '';
|
||||||
taskData['activity'] ?? '';
|
v.getController('team_size')?.text = data['teamSize']?.toString() ?? '';
|
||||||
controller.basicValidator.getController('team_size')?.text =
|
v.getController('assigned')?.text = data['assigned'] ?? '';
|
||||||
taskData['teamSize']?.toString() ?? '';
|
v.getController('task_id')?.text = data['taskId'] ?? '';
|
||||||
controller.basicValidator.getController('assigned')?.text =
|
v.getController('completed_work')?.clear();
|
||||||
taskData['assigned'] ?? '';
|
v.getController('comment')?.clear();
|
||||||
controller.basicValidator.getController('task_id')?.text =
|
|
||||||
taskData['taskId'] ?? '';
|
|
||||||
controller.basicValidator.getController('completed_work')?.clear();
|
|
||||||
controller.basicValidator.getController('comment')?.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Obx(() {
|
||||||
decoration: BoxDecoration(
|
return BaseBottomSheet(
|
||||||
color: Colors.white,
|
title: "Report Task",
|
||||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
|
isSubmitting: controller.reportStatus.value == ApiStatus.loading,
|
||||||
),
|
onCancel: () => Navigator.of(context).pop(),
|
||||||
child: SingleChildScrollView(
|
onSubmit: _handleSubmit,
|
||||||
padding: EdgeInsets.only(
|
child: Form(
|
||||||
bottom: MediaQuery.of(context).viewInsets.bottom + 24,
|
key: controller.basicValidator.formKey,
|
||||||
left: 24,
|
child: Column(
|
||||||
right: 24,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
top: 12,
|
children: [
|
||||||
),
|
_buildRow("Assigned Date", controller.basicValidator.getController('assigned_date')?.text),
|
||||||
child: Column(
|
_buildRow("Assigned By", controller.basicValidator.getController('assigned_by')?.text),
|
||||||
mainAxisSize: MainAxisSize.min,
|
_buildRow("Work Area", controller.basicValidator.getController('work_area')?.text),
|
||||||
children: [
|
_buildRow("Activity", controller.basicValidator.getController('activity')?.text),
|
||||||
// Drag handle
|
_buildRow("Team Size", controller.basicValidator.getController('team_size')?.text),
|
||||||
Container(
|
_buildRow(
|
||||||
width: 40,
|
"Assigned",
|
||||||
height: 4,
|
"${controller.basicValidator.getController('assigned')?.text ?? '-'} "
|
||||||
margin: const EdgeInsets.only(bottom: 12),
|
"of ${widget.taskData['pendingWork'] ?? '-'} Pending",
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.grey.shade400,
|
|
||||||
borderRadius: BorderRadius.circular(2),
|
|
||||||
),
|
),
|
||||||
),
|
_buildCompletedWorkField(),
|
||||||
GetBuilder<ReportTaskController>(
|
_buildCommentField(),
|
||||||
tag: widget.taskData['taskId'] ?? '',
|
Obx(() => _buildImageSection()),
|
||||||
init: controller,
|
],
|
||||||
builder: (_) {
|
|
||||||
return Form(
|
|
||||||
key: controller.basicValidator.formKey,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Center(
|
|
||||||
child: MyText.titleMedium(
|
|
||||||
"Report Task",
|
|
||||||
fontWeight: 600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
MySpacing.height(16),
|
|
||||||
buildRow(
|
|
||||||
"Assigned Date",
|
|
||||||
controller.basicValidator
|
|
||||||
.getController('assigned_date')
|
|
||||||
?.text
|
|
||||||
.trim()),
|
|
||||||
buildRow(
|
|
||||||
"Assigned By",
|
|
||||||
controller.basicValidator
|
|
||||||
.getController('assigned_by')
|
|
||||||
?.text
|
|
||||||
.trim()),
|
|
||||||
buildRow(
|
|
||||||
"Work Area",
|
|
||||||
controller.basicValidator
|
|
||||||
.getController('work_area')
|
|
||||||
?.text
|
|
||||||
.trim()),
|
|
||||||
buildRow(
|
|
||||||
"Activity",
|
|
||||||
controller.basicValidator
|
|
||||||
.getController('activity')
|
|
||||||
?.text
|
|
||||||
.trim()),
|
|
||||||
buildRow(
|
|
||||||
"Team Size",
|
|
||||||
controller.basicValidator
|
|
||||||
.getController('team_size')
|
|
||||||
?.text
|
|
||||||
.trim()),
|
|
||||||
buildRow(
|
|
||||||
"Assigned",
|
|
||||||
"${controller.basicValidator.getController('assigned')?.text.trim()} "
|
|
||||||
"of ${widget.taskData['pendingWork'] ?? '-'} Pending"),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.work_outline,
|
|
||||||
size: 18, color: Colors.grey[700]),
|
|
||||||
MySpacing.width(8),
|
|
||||||
MyText.titleSmall(
|
|
||||||
"Completed Work:",
|
|
||||||
fontWeight: 600,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
MySpacing.height(8),
|
|
||||||
TextFormField(
|
|
||||||
validator: (value) {
|
|
||||||
if (value == null || value.trim().isEmpty) {
|
|
||||||
return 'Please enter completed work';
|
|
||||||
}
|
|
||||||
final completed = int.tryParse(value.trim());
|
|
||||||
final pending = widget.taskData['pendingWork'] ?? 0;
|
|
||||||
|
|
||||||
if (completed == null) {
|
|
||||||
return 'Enter a valid number';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (completed > pending) {
|
|
||||||
return 'Completed work cannot exceed pending work $pending';
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
controller: controller.basicValidator
|
|
||||||
.getController('completed_work'),
|
|
||||||
keyboardType: TextInputType.number,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
hintText: "eg: 10",
|
|
||||||
hintStyle: MyTextStyle.bodySmall(xMuted: true),
|
|
||||||
border: outlineInputBorder,
|
|
||||||
enabledBorder: outlineInputBorder,
|
|
||||||
focusedBorder: focusedInputBorder,
|
|
||||||
contentPadding: MySpacing.all(16),
|
|
||||||
isCollapsed: true,
|
|
||||||
floatingLabelBehavior: FloatingLabelBehavior.never,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
MySpacing.height(24),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.comment_outlined,
|
|
||||||
size: 18, color: Colors.grey[700]),
|
|
||||||
MySpacing.width(8),
|
|
||||||
MyText.titleSmall(
|
|
||||||
"Comment:",
|
|
||||||
fontWeight: 600,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
MySpacing.height(8),
|
|
||||||
TextFormField(
|
|
||||||
validator: controller.basicValidator
|
|
||||||
.getValidation('comment'),
|
|
||||||
controller: controller.basicValidator
|
|
||||||
.getController('comment'),
|
|
||||||
keyboardType: TextInputType.text,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
hintText: "eg: Work done successfully",
|
|
||||||
hintStyle: MyTextStyle.bodySmall(xMuted: true),
|
|
||||||
border: outlineInputBorder,
|
|
||||||
enabledBorder: outlineInputBorder,
|
|
||||||
focusedBorder: focusedInputBorder,
|
|
||||||
contentPadding: MySpacing.all(16),
|
|
||||||
isCollapsed: true,
|
|
||||||
floatingLabelBehavior: FloatingLabelBehavior.never,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
MySpacing.height(24),
|
|
||||||
Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.camera_alt_outlined,
|
|
||||||
size: 18, color: Colors.grey[700]),
|
|
||||||
MySpacing.width(8),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
MyText.titleSmall("Attach Photos:",
|
|
||||||
fontWeight: 600),
|
|
||||||
MySpacing.height(12),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Obx(() {
|
|
||||||
final images = controller.selectedImages;
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
if (images.isEmpty)
|
|
||||||
Container(
|
|
||||||
height: 70,
|
|
||||||
width: double.infinity,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
border: Border.all(
|
|
||||||
color: Colors.grey.shade300, width: 2),
|
|
||||||
color: Colors.grey.shade100,
|
|
||||||
),
|
|
||||||
child: Center(
|
|
||||||
child: Icon(Icons.photo_camera_outlined,
|
|
||||||
size: 48, color: Colors.grey.shade400),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
else
|
|
||||||
SizedBox(
|
|
||||||
height: 70,
|
|
||||||
child: ListView.separated(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
itemCount: images.length,
|
|
||||||
separatorBuilder: (_, __) =>
|
|
||||||
MySpacing.width(12),
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final file = images[index];
|
|
||||||
return Stack(
|
|
||||||
children: [
|
|
||||||
GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (_) => Dialog(
|
|
||||||
child: InteractiveViewer(
|
|
||||||
child: Image.file(file),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: ClipRRect(
|
|
||||||
borderRadius:
|
|
||||||
BorderRadius.circular(12),
|
|
||||||
child: Image.file(
|
|
||||||
file,
|
|
||||||
height: 70,
|
|
||||||
width: 70,
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
top: 4,
|
|
||||||
right: 4,
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () => controller
|
|
||||||
.removeImageAt(index),
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.black54,
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
),
|
|
||||||
child: Icon(Icons.close,
|
|
||||||
size: 20,
|
|
||||||
color: Colors.white),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
MySpacing.height(16),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: MyButton.outlined(
|
|
||||||
onPressed: () => controller.pickImages(
|
|
||||||
fromCamera: true),
|
|
||||||
padding: MySpacing.xy(12, 10),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.camera_alt,
|
|
||||||
size: 16,
|
|
||||||
color: Colors.blueAccent),
|
|
||||||
MySpacing.width(6),
|
|
||||||
MyText.bodySmall('Capture',
|
|
||||||
color: Colors.blueAccent),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
MySpacing.width(12),
|
|
||||||
Expanded(
|
|
||||||
child: MyButton.outlined(
|
|
||||||
onPressed: () => controller.pickImages(
|
|
||||||
fromCamera: false),
|
|
||||||
padding: MySpacing.xy(12, 10),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.upload_file,
|
|
||||||
size: 16,
|
|
||||||
color: Colors.blueAccent),
|
|
||||||
MySpacing.width(6),
|
|
||||||
MyText.bodySmall('Upload',
|
|
||||||
color: Colors.blueAccent),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: OutlinedButton.icon(
|
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
|
||||||
icon: const Icon(Icons.close, color: Colors.red, size: 18),
|
|
||||||
label: MyText.bodyMedium(
|
|
||||||
"Cancel",
|
|
||||||
color: Colors.red,
|
|
||||||
fontWeight: 600,
|
|
||||||
),
|
|
||||||
style: OutlinedButton.styleFrom(
|
|
||||||
side: const BorderSide(color: Colors.red),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
),
|
});
|
||||||
const SizedBox(width: 16),
|
|
||||||
Expanded(
|
|
||||||
child: Obx(() {
|
|
||||||
final isLoading =
|
|
||||||
controller.reportStatus.value == ApiStatus.loading;
|
|
||||||
|
|
||||||
return ElevatedButton.icon(
|
|
||||||
onPressed: isLoading
|
|
||||||
? null
|
|
||||||
: () async {
|
|
||||||
if (controller.basicValidator.validateForm()) {
|
|
||||||
final success = await controller.reportTask(
|
|
||||||
projectId: controller.basicValidator
|
|
||||||
.getController('task_id')
|
|
||||||
?.text ??
|
|
||||||
'',
|
|
||||||
comment: controller.basicValidator
|
|
||||||
.getController('comment')
|
|
||||||
?.text ??
|
|
||||||
'',
|
|
||||||
completedTask: int.tryParse(
|
|
||||||
controller.basicValidator
|
|
||||||
.getController('completed_work')
|
|
||||||
?.text ??
|
|
||||||
'') ??
|
|
||||||
0,
|
|
||||||
checklist: [],
|
|
||||||
reportedDate: DateTime.now(),
|
|
||||||
images: controller.selectedImages,
|
|
||||||
);
|
|
||||||
if (success && widget.onReportSuccess != null) {
|
|
||||||
widget.onReportSuccess!();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
icon: isLoading
|
|
||||||
? const SizedBox(
|
|
||||||
height: 16,
|
|
||||||
width: 16,
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
strokeWidth: 2,
|
|
||||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: const Icon(Icons.check_circle_outline,
|
|
||||||
color: Colors.white, size: 18),
|
|
||||||
label: isLoading
|
|
||||||
? const SizedBox.shrink()
|
|
||||||
: MyText.bodyMedium(
|
|
||||||
"Report",
|
|
||||||
color: Colors.white,
|
|
||||||
fontWeight: 600,
|
|
||||||
),
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.indigo,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildRow(String label, String? value) {
|
Future<void> _handleSubmit() async {
|
||||||
IconData icon;
|
final v = controller.basicValidator;
|
||||||
switch (label) {
|
|
||||||
case "Assigned Date":
|
if (v.validateForm()) {
|
||||||
icon = Icons.calendar_today_outlined;
|
final success = await controller.reportTask(
|
||||||
break;
|
projectId: v.getController('task_id')?.text ?? '',
|
||||||
case "Assigned By":
|
comment: v.getController('comment')?.text ?? '',
|
||||||
icon = Icons.person_outline;
|
completedTask: int.tryParse(v.getController('completed_work')?.text ?? '') ?? 0,
|
||||||
break;
|
checklist: [],
|
||||||
case "Work Area":
|
reportedDate: DateTime.now(),
|
||||||
icon = Icons.place_outlined;
|
images: controller.selectedImages,
|
||||||
break;
|
);
|
||||||
case "Activity":
|
|
||||||
icon = Icons.run_circle_outlined;
|
if (success) {
|
||||||
break;
|
widget.onReportSuccess?.call();
|
||||||
case "Team Size":
|
}
|
||||||
icon = Icons.group_outlined;
|
|
||||||
break;
|
|
||||||
case "Assigned":
|
|
||||||
icon = Icons.assignment_turned_in_outlined;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
icon = Icons.info_outline;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildRow(String label, String? value) {
|
||||||
|
final icons = {
|
||||||
|
"Assigned Date": Icons.calendar_today_outlined,
|
||||||
|
"Assigned By": Icons.person_outline,
|
||||||
|
"Work Area": Icons.place_outlined,
|
||||||
|
"Activity": Icons.run_circle_outlined,
|
||||||
|
"Team Size": Icons.group_outlined,
|
||||||
|
"Assigned": Icons.assignment_turned_in_outlined,
|
||||||
|
};
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 16),
|
padding: const EdgeInsets.only(bottom: 16),
|
||||||
child: Row(
|
child: Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Icon(icon, size: 18, color: Colors.grey[700]),
|
Icon(icons[label] ?? Icons.info_outline, size: 18, color: Colors.grey[700]),
|
||||||
MySpacing.width(8),
|
MySpacing.width(8),
|
||||||
MyText.titleSmall(
|
MyText.titleSmall("$label:", fontWeight: 600),
|
||||||
"$label:",
|
|
||||||
fontWeight: 600,
|
|
||||||
),
|
|
||||||
MySpacing.width(12),
|
MySpacing.width(12),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: MyText.bodyMedium(value?.isNotEmpty == true ? value! : "-"),
|
child: MyText.bodyMedium(value?.trim().isNotEmpty == true ? value!.trim() : "-"),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Widget _buildCompletedWorkField() {
|
||||||
|
final pending = widget.taskData['pendingWork'] ?? 0;
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.work_outline, size: 18, color: Colors.grey[700]),
|
||||||
|
MySpacing.width(8),
|
||||||
|
MyText.titleSmall("Completed Work:", fontWeight: 600),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
MySpacing.height(8),
|
||||||
|
TextFormField(
|
||||||
|
controller: controller.basicValidator.getController('completed_work'),
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
validator: (value) {
|
||||||
|
if (value == null || value.trim().isEmpty) return 'Please enter completed work';
|
||||||
|
final completed = int.tryParse(value.trim());
|
||||||
|
if (completed == null) return 'Enter a valid number';
|
||||||
|
if (completed > pending) return 'Completed work cannot exceed pending work $pending';
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: "eg: 10",
|
||||||
|
hintStyle: MyTextStyle.bodySmall(xMuted: true),
|
||||||
|
border: outlineInputBorder,
|
||||||
|
enabledBorder: outlineInputBorder,
|
||||||
|
focusedBorder: focusedInputBorder,
|
||||||
|
contentPadding: MySpacing.all(16),
|
||||||
|
isCollapsed: true,
|
||||||
|
floatingLabelBehavior: FloatingLabelBehavior.never,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
MySpacing.height(24),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildCommentField() {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.comment_outlined, size: 18, color: Colors.grey[700]),
|
||||||
|
MySpacing.width(8),
|
||||||
|
MyText.titleSmall("Comment:", fontWeight: 600),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
MySpacing.height(8),
|
||||||
|
TextFormField(
|
||||||
|
controller: controller.basicValidator.getController('comment'),
|
||||||
|
validator: controller.basicValidator.getValidation('comment'),
|
||||||
|
keyboardType: TextInputType.text,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: "eg: Work done successfully",
|
||||||
|
hintStyle: MyTextStyle.bodySmall(xMuted: true),
|
||||||
|
border: outlineInputBorder,
|
||||||
|
enabledBorder: outlineInputBorder,
|
||||||
|
focusedBorder: focusedInputBorder,
|
||||||
|
contentPadding: MySpacing.all(16),
|
||||||
|
isCollapsed: true,
|
||||||
|
floatingLabelBehavior: FloatingLabelBehavior.never,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
MySpacing.height(24),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildImageSection() {
|
||||||
|
final images = controller.selectedImages;
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.camera_alt_outlined, size: 18, color: Colors.grey[700]),
|
||||||
|
MySpacing.width(8),
|
||||||
|
MyText.titleSmall("Attach Photos:", fontWeight: 600),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
MySpacing.height(12),
|
||||||
|
if (images.isEmpty)
|
||||||
|
Container(
|
||||||
|
height: 70,
|
||||||
|
width: double.infinity,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
border: Border.all(color: Colors.grey.shade300, width: 2),
|
||||||
|
color: Colors.grey.shade100,
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Icon(Icons.photo_camera_outlined, size: 48, color: Colors.grey.shade400),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
SizedBox(
|
||||||
|
height: 70,
|
||||||
|
child: ListView.separated(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
itemCount: images.length,
|
||||||
|
separatorBuilder: (_, __) => MySpacing.width(12),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final file = images[index];
|
||||||
|
return Stack(
|
||||||
|
children: [
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => Dialog(
|
||||||
|
child: InteractiveViewer(child: Image.file(file)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
child: Image.file(file, height: 70, width: 70, fit: BoxFit.cover),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
top: 4,
|
||||||
|
right: 4,
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () => controller.removeImageAt(index),
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(color: Colors.black54, shape: BoxShape.circle),
|
||||||
|
child: const Icon(Icons.close, size: 20, color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
MySpacing.height(16),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: MyButton.outlined(
|
||||||
|
onPressed: () => controller.pickImages(fromCamera: true),
|
||||||
|
padding: MySpacing.xy(12, 10),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.camera_alt, size: 16, color: Colors.blueAccent),
|
||||||
|
MySpacing.width(6),
|
||||||
|
MyText.bodySmall('Capture', color: Colors.blueAccent),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
MySpacing.width(12),
|
||||||
|
Expanded(
|
||||||
|
child: MyButton.outlined(
|
||||||
|
onPressed: () => controller.pickImages(fromCamera: false),
|
||||||
|
padding: MySpacing.xy(12, 10),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.upload_file, size: 16, color: Colors.blueAccent),
|
||||||
|
MySpacing.width(6),
|
||||||
|
MyText.bodySmall('Upload', color: Colors.blueAccent),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -18,30 +18,9 @@ class ExpenseFilterBottomSheet extends StatelessWidget {
|
|||||||
required this.scrollController,
|
required this.scrollController,
|
||||||
});
|
});
|
||||||
|
|
||||||
InputDecoration _inputDecoration(String hint) {
|
|
||||||
return InputDecoration(
|
|
||||||
hintText: hint,
|
|
||||||
hintStyle: MyTextStyle.bodySmall(xMuted: true),
|
|
||||||
filled: true,
|
|
||||||
fillColor: Colors.grey.shade100,
|
|
||||||
border: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: Colors.grey.shade300),
|
|
||||||
),
|
|
||||||
enabledBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: Colors.grey.shade300),
|
|
||||||
),
|
|
||||||
focusedBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: const BorderSide(color: Colors.blueAccent, width: 1.5),
|
|
||||||
),
|
|
||||||
contentPadding: MySpacing.all(12),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
// Obx rebuilds the widget when observable values from the controller change.
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
return BaseBottomSheet(
|
return BaseBottomSheet(
|
||||||
title: 'Filter Expenses',
|
title: 'Filter Expenses',
|
||||||
@ -72,89 +51,15 @@ class ExpenseFilterBottomSheet extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
MySpacing.height(8),
|
MySpacing.height(8),
|
||||||
|
_buildProjectFilter(context),
|
||||||
_buildField("Project", _popupSelector(
|
|
||||||
context,
|
|
||||||
currentValue: expenseController.selectedProject.value.isEmpty
|
|
||||||
? 'Select Project'
|
|
||||||
: expenseController.selectedProject.value,
|
|
||||||
items: expenseController.globalProjects,
|
|
||||||
onSelected: (value) =>
|
|
||||||
expenseController.selectedProject.value = value,
|
|
||||||
)),
|
|
||||||
MySpacing.height(16),
|
MySpacing.height(16),
|
||||||
|
_buildStatusFilter(context),
|
||||||
_buildField("Expense Status", _popupSelector(
|
|
||||||
context,
|
|
||||||
currentValue: expenseController.selectedStatus.value.isEmpty
|
|
||||||
? 'Select Expense Status'
|
|
||||||
: expenseController.expenseStatuses
|
|
||||||
.firstWhereOrNull((e) =>
|
|
||||||
e.id == expenseController.selectedStatus.value)
|
|
||||||
?.name ??
|
|
||||||
'Select Expense Status',
|
|
||||||
items: expenseController.expenseStatuses
|
|
||||||
.map((e) => e.name)
|
|
||||||
.toList(),
|
|
||||||
onSelected: (name) {
|
|
||||||
final status = expenseController.expenseStatuses
|
|
||||||
.firstWhere((e) => e.name == name);
|
|
||||||
expenseController.selectedStatus.value = status.id;
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
MySpacing.height(16),
|
MySpacing.height(16),
|
||||||
|
_buildDateRangeFilter(context),
|
||||||
_buildField("Date Range", Row(
|
|
||||||
children: [
|
|
||||||
Expanded(child: _dateButton(
|
|
||||||
label: expenseController.startDate.value == null
|
|
||||||
? 'Start Date'
|
|
||||||
: DateTimeUtils.formatDate(
|
|
||||||
expenseController.startDate.value!, 'dd MMM yyyy'),
|
|
||||||
onTap: () async {
|
|
||||||
DateTime? picked = await showDatePicker(
|
|
||||||
context: context,
|
|
||||||
initialDate:
|
|
||||||
expenseController.startDate.value ?? DateTime.now(),
|
|
||||||
firstDate: DateTime(2020),
|
|
||||||
lastDate: DateTime.now().add(const Duration(days: 365)),
|
|
||||||
);
|
|
||||||
if (picked != null) {
|
|
||||||
expenseController.startDate.value = picked;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
MySpacing.width(8),
|
|
||||||
Expanded(child: _dateButton(
|
|
||||||
label: expenseController.endDate.value == null
|
|
||||||
? 'End Date'
|
|
||||||
: DateTimeUtils.formatDate(
|
|
||||||
expenseController.endDate.value!, 'dd MMM yyyy'),
|
|
||||||
onTap: () async {
|
|
||||||
DateTime? picked = await showDatePicker(
|
|
||||||
context: context,
|
|
||||||
initialDate:
|
|
||||||
expenseController.endDate.value ?? DateTime.now(),
|
|
||||||
firstDate: DateTime(2020),
|
|
||||||
lastDate: DateTime.now().add(const Duration(days: 365)),
|
|
||||||
);
|
|
||||||
if (picked != null) {
|
|
||||||
expenseController.endDate.value = picked;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
],
|
|
||||||
)),
|
|
||||||
MySpacing.height(16),
|
MySpacing.height(16),
|
||||||
|
_buildPaidByFilter(),
|
||||||
_buildField("Paid By", _employeeSelector(
|
|
||||||
selectedEmployees: expenseController.selectedPaidByEmployees,
|
|
||||||
)),
|
|
||||||
MySpacing.height(16),
|
MySpacing.height(16),
|
||||||
|
_buildCreatedByFilter(),
|
||||||
_buildField("Created By", _employeeSelector(
|
|
||||||
selectedEmployees: expenseController.selectedCreatedByEmployees,
|
|
||||||
)),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -162,6 +67,7 @@ class ExpenseFilterBottomSheet extends StatelessWidget {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Builds a generic field layout with a label and a child widget.
|
||||||
Widget _buildField(String label, Widget child) {
|
Widget _buildField(String label, Widget child) {
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
@ -173,6 +79,179 @@ class ExpenseFilterBottomSheet extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Extracted widget builder for the Project filter.
|
||||||
|
Widget _buildProjectFilter(BuildContext context) {
|
||||||
|
return _buildField(
|
||||||
|
"Project",
|
||||||
|
_popupSelector(
|
||||||
|
context,
|
||||||
|
currentValue: expenseController.selectedProject.value.isEmpty
|
||||||
|
? 'Select Project'
|
||||||
|
: expenseController.selectedProject.value,
|
||||||
|
items: expenseController.globalProjects,
|
||||||
|
onSelected: (value) => expenseController.selectedProject.value = value,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extracted widget builder for the Expense Status filter.
|
||||||
|
Widget _buildStatusFilter(BuildContext context) {
|
||||||
|
return _buildField(
|
||||||
|
"Expense Status",
|
||||||
|
_popupSelector(
|
||||||
|
context,
|
||||||
|
currentValue: expenseController.selectedStatus.value.isEmpty
|
||||||
|
? 'Select Expense Status'
|
||||||
|
: expenseController.expenseStatuses
|
||||||
|
.firstWhereOrNull(
|
||||||
|
(e) => e.id == expenseController.selectedStatus.value)
|
||||||
|
?.name ??
|
||||||
|
'Select Expense Status',
|
||||||
|
items: expenseController.expenseStatuses.map((e) => e.name).toList(),
|
||||||
|
onSelected: (name) {
|
||||||
|
final status = expenseController.expenseStatuses
|
||||||
|
.firstWhere((e) => e.name == name);
|
||||||
|
expenseController.selectedStatus.value = status.id;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extracted widget builder for the Date Range filter.
|
||||||
|
Widget _buildDateRangeFilter(BuildContext context) {
|
||||||
|
return _buildField(
|
||||||
|
"Date Filter",
|
||||||
|
Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Obx(() {
|
||||||
|
return SegmentedButton<String>(
|
||||||
|
segments: expenseController.dateTypes
|
||||||
|
.map(
|
||||||
|
(type) => ButtonSegment(
|
||||||
|
value: type,
|
||||||
|
label: Text(
|
||||||
|
type,
|
||||||
|
style: MyTextStyle.bodySmall(
|
||||||
|
fontWeight: 600,
|
||||||
|
fontSize: 13,
|
||||||
|
height: 1.2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
selected: {expenseController.selectedDateType.value},
|
||||||
|
onSelectionChanged: (newSelection) {
|
||||||
|
if (newSelection.isNotEmpty) {
|
||||||
|
expenseController.selectedDateType.value = newSelection.first;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
style: ButtonStyle(
|
||||||
|
visualDensity: const VisualDensity(horizontal: -2, vertical: -2),
|
||||||
|
padding: MaterialStateProperty.all(
|
||||||
|
const EdgeInsets.symmetric(horizontal: 8, vertical: 6)),
|
||||||
|
backgroundColor: MaterialStateProperty.resolveWith(
|
||||||
|
(states) => states.contains(MaterialState.selected)
|
||||||
|
? Colors.indigo.shade100
|
||||||
|
: Colors.grey.shade100,
|
||||||
|
),
|
||||||
|
foregroundColor: MaterialStateProperty.resolveWith(
|
||||||
|
(states) => states.contains(MaterialState.selected)
|
||||||
|
? Colors.indigo
|
||||||
|
: Colors.black87,
|
||||||
|
),
|
||||||
|
shape: MaterialStateProperty.all(
|
||||||
|
RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
side: MaterialStateProperty.resolveWith(
|
||||||
|
(states) => BorderSide(
|
||||||
|
color: states.contains(MaterialState.selected)
|
||||||
|
? Colors.indigo
|
||||||
|
: Colors.grey.shade300,
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
MySpacing.height(16),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: _dateButton(
|
||||||
|
label: expenseController.startDate.value == null
|
||||||
|
? 'Start Date'
|
||||||
|
: DateTimeUtils.formatDate(
|
||||||
|
expenseController.startDate.value!, 'dd MMM yyyy'),
|
||||||
|
onTap: () => _selectDate(
|
||||||
|
context,
|
||||||
|
expenseController.startDate,
|
||||||
|
lastDate: expenseController.endDate.value,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
MySpacing.width(12),
|
||||||
|
Expanded(
|
||||||
|
child: _dateButton(
|
||||||
|
label: expenseController.endDate.value == null
|
||||||
|
? 'End Date'
|
||||||
|
: DateTimeUtils.formatDate(
|
||||||
|
expenseController.endDate.value!, 'dd MMM yyyy'),
|
||||||
|
onTap: () => _selectDate(
|
||||||
|
context,
|
||||||
|
expenseController.endDate,
|
||||||
|
firstDate: expenseController.startDate.value,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Extracted widget builder for the "Paid By" employee filter.
|
||||||
|
Widget _buildPaidByFilter() {
|
||||||
|
return _buildField(
|
||||||
|
"Paid By",
|
||||||
|
_employeeSelector(
|
||||||
|
selectedEmployees: expenseController.selectedPaidByEmployees),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extracted widget builder for the "Created By" employee filter.
|
||||||
|
Widget _buildCreatedByFilter() {
|
||||||
|
return _buildField(
|
||||||
|
"Created By",
|
||||||
|
_employeeSelector(
|
||||||
|
selectedEmployees: expenseController.selectedCreatedByEmployees),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helper method to show a date picker and update the state.
|
||||||
|
Future<void> _selectDate(
|
||||||
|
BuildContext context,
|
||||||
|
Rx<DateTime?> dateNotifier, {
|
||||||
|
DateTime? firstDate,
|
||||||
|
DateTime? lastDate,
|
||||||
|
}) async {
|
||||||
|
final DateTime? picked = await showDatePicker(
|
||||||
|
context: context,
|
||||||
|
initialDate: dateNotifier.value ?? DateTime.now(),
|
||||||
|
firstDate: firstDate ?? DateTime(2020),
|
||||||
|
lastDate: lastDate ?? DateTime.now().add(const Duration(days: 365)),
|
||||||
|
);
|
||||||
|
if (picked != null && picked != dateNotifier.value) {
|
||||||
|
dateNotifier.value = picked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reusable popup selector widget.
|
||||||
Widget _popupSelector(
|
Widget _popupSelector(
|
||||||
BuildContext context, {
|
BuildContext context, {
|
||||||
required String currentValue,
|
required String currentValue,
|
||||||
@ -212,6 +291,7 @@ class ExpenseFilterBottomSheet extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reusable date button widget.
|
||||||
Widget _dateButton({required String label, required VoidCallback onTap}) {
|
Widget _dateButton({required String label, required VoidCallback onTap}) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
@ -227,9 +307,11 @@ class ExpenseFilterBottomSheet extends StatelessWidget {
|
|||||||
const Icon(Icons.calendar_today, size: 16, color: Colors.grey),
|
const Icon(Icons.calendar_today, size: 16, color: Colors.grey),
|
||||||
MySpacing.width(8),
|
MySpacing.width(8),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(label,
|
child: Text(
|
||||||
style: MyTextStyle.bodyMedium(),
|
label,
|
||||||
overflow: TextOverflow.ellipsis),
|
style: MyTextStyle.bodyMedium(),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -237,24 +319,28 @@ class ExpenseFilterBottomSheet extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _employeeSelector({
|
/// Reusable employee selector with Autocomplete.
|
||||||
required RxList<EmployeeModel> selectedEmployees,
|
Widget _employeeSelector({required RxList<EmployeeModel> selectedEmployees}) {
|
||||||
}) {
|
final textController = TextEditingController();
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Obx(() {
|
Obx(() {
|
||||||
|
if (selectedEmployees.isEmpty) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
return Wrap(
|
return Wrap(
|
||||||
spacing: 8,
|
spacing: 8,
|
||||||
runSpacing: -8,
|
runSpacing: 0,
|
||||||
children: selectedEmployees.map((emp) {
|
children: selectedEmployees
|
||||||
return Chip(
|
.map((emp) => Chip(
|
||||||
label: Text(emp.name),
|
label: Text(emp.name),
|
||||||
onDeleted: () => selectedEmployees.remove(emp),
|
onDeleted: () => selectedEmployees.remove(emp),
|
||||||
deleteIcon: const Icon(Icons.close, size: 18),
|
deleteIcon: const Icon(Icons.close, size: 18),
|
||||||
backgroundColor: Colors.grey.shade200,
|
backgroundColor: Colors.grey.shade200,
|
||||||
);
|
padding: const EdgeInsets.all(8),
|
||||||
}).toList(),
|
))
|
||||||
|
.toList(),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
MySpacing.height(8),
|
MySpacing.height(8),
|
||||||
@ -263,10 +349,12 @@ class ExpenseFilterBottomSheet extends StatelessWidget {
|
|||||||
if (textEditingValue.text.isEmpty) {
|
if (textEditingValue.text.isEmpty) {
|
||||||
return const Iterable<EmployeeModel>.empty();
|
return const Iterable<EmployeeModel>.empty();
|
||||||
}
|
}
|
||||||
return expenseController.allEmployees.where((EmployeeModel emp) {
|
return expenseController.allEmployees.where((emp) {
|
||||||
return emp.name
|
final isNotSelected = !selectedEmployees.contains(emp);
|
||||||
|
final matchesQuery = emp.name
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.contains(textEditingValue.text.toLowerCase());
|
.contains(textEditingValue.text.toLowerCase());
|
||||||
|
return isNotSelected && matchesQuery;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
displayStringForOption: (EmployeeModel emp) => emp.name,
|
displayStringForOption: (EmployeeModel emp) => emp.name,
|
||||||
@ -274,12 +362,21 @@ class ExpenseFilterBottomSheet extends StatelessWidget {
|
|||||||
if (!selectedEmployees.contains(emp)) {
|
if (!selectedEmployees.contains(emp)) {
|
||||||
selectedEmployees.add(emp);
|
selectedEmployees.add(emp);
|
||||||
}
|
}
|
||||||
|
textController.clear();
|
||||||
},
|
},
|
||||||
fieldViewBuilder: (context, controller, focusNode, _) {
|
fieldViewBuilder: (context, controller, focusNode, onFieldSubmitted) {
|
||||||
|
// Assign the local controller to the one from the builder
|
||||||
|
// to allow clearing it on selection.
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (textController != controller) {
|
||||||
|
// This is a workaround to sync controllers
|
||||||
|
}
|
||||||
|
});
|
||||||
return TextField(
|
return TextField(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
focusNode: focusNode,
|
focusNode: focusNode,
|
||||||
decoration: _inputDecoration("Search Employee"),
|
decoration: _inputDecoration("Search Employee"),
|
||||||
|
onSubmitted: (_) => onFieldSubmitted(),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
optionsViewBuilder: (context, onSelected, options) {
|
optionsViewBuilder: (context, onSelected, options) {
|
||||||
@ -288,9 +385,10 @@ class ExpenseFilterBottomSheet extends StatelessWidget {
|
|||||||
child: Material(
|
child: Material(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
elevation: 4.0,
|
elevation: 4.0,
|
||||||
child: SizedBox(
|
child: ConstrainedBox(
|
||||||
height: 200,
|
constraints: const BoxConstraints(maxHeight: 200),
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
itemCount: options.length,
|
itemCount: options.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final emp = options.elementAt(index);
|
final emp = options.elementAt(index);
|
||||||
@ -308,4 +406,27 @@ class ExpenseFilterBottomSheet extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Centralized decoration for text fields.
|
||||||
|
InputDecoration _inputDecoration(String hint) {
|
||||||
|
return InputDecoration(
|
||||||
|
hintText: hint,
|
||||||
|
hintStyle: MyTextStyle.bodySmall(xMuted: true),
|
||||||
|
filled: true,
|
||||||
|
fillColor: Colors.grey.shade100,
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: Colors.grey.shade300),
|
||||||
|
),
|
||||||
|
enabledBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: Colors.grey.shade300),
|
||||||
|
),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: const BorderSide(color: Colors.blueAccent, width: 1.5),
|
||||||
|
),
|
||||||
|
contentPadding: MySpacing.all(12),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
import 'package:marco/controller/project_controller.dart';
|
import 'package:marco/controller/project_controller.dart';
|
||||||
import 'package:marco/controller/expense/expense_screen_controller.dart';
|
import 'package:marco/controller/expense/expense_screen_controller.dart';
|
||||||
import 'package:marco/helpers/utils/date_time_utils.dart';
|
import 'package:marco/helpers/utils/date_time_utils.dart';
|
||||||
@ -19,9 +20,9 @@ class ExpenseMainScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ExpenseMainScreenState extends State<ExpenseMainScreen> {
|
class _ExpenseMainScreenState extends State<ExpenseMainScreen> {
|
||||||
final RxBool isHistoryView = false.obs;
|
bool isHistoryView = false;
|
||||||
final TextEditingController searchController = TextEditingController();
|
final searchController = TextEditingController();
|
||||||
final RxString searchQuery = ''.obs;
|
String searchQuery = '';
|
||||||
|
|
||||||
final ProjectController projectController = Get.find<ProjectController>();
|
final ProjectController projectController = Get.find<ProjectController>();
|
||||||
final ExpenseController expenseController = Get.put(ExpenseController());
|
final ExpenseController expenseController = Get.put(ExpenseController());
|
||||||
@ -29,27 +30,40 @@ class _ExpenseMainScreenState extends State<ExpenseMainScreen> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
expenseController.fetchExpenses(); // Initial data load
|
|
||||||
}
|
|
||||||
|
|
||||||
void _refreshExpenses() {
|
|
||||||
expenseController.fetchExpenses();
|
expenseController.fetchExpenses();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _openFilterBottomSheet(BuildContext context) {
|
void _refreshExpenses() => expenseController.fetchExpenses();
|
||||||
|
void _openFilterBottomSheet() {
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
builder: (context) {
|
builder: (_) => ExpenseFilterBottomSheet(
|
||||||
return ExpenseFilterBottomSheet(
|
expenseController: expenseController,
|
||||||
expenseController: expenseController,
|
scrollController: ScrollController(),
|
||||||
scrollController: ScrollController(),
|
),
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<ExpenseModel> _getFilteredExpenses() {
|
||||||
|
final lowerQuery = searchQuery.trim().toLowerCase();
|
||||||
|
final now = DateTime.now();
|
||||||
|
final filtered = expenseController.expenses.where((e) {
|
||||||
|
return lowerQuery.isEmpty ||
|
||||||
|
e.expensesType.name.toLowerCase().contains(lowerQuery) ||
|
||||||
|
e.supplerName.toLowerCase().contains(lowerQuery) ||
|
||||||
|
e.paymentMode.name.toLowerCase().contains(lowerQuery);
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
filtered.sort((a, b) => b.transactionDate.compareTo(a.transactionDate));
|
||||||
|
|
||||||
|
return isHistoryView
|
||||||
|
? filtered.where((e) => e.transactionDate.isBefore(DateTime(now.year, now.month, 1))).toList()
|
||||||
|
: filtered.where((e) =>
|
||||||
|
e.transactionDate.month == now.month && e.transactionDate.year == now.year).toList();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -59,18 +73,21 @@ class _ExpenseMainScreenState extends State<ExpenseMainScreen> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
_SearchAndFilter(
|
_SearchAndFilter(
|
||||||
searchController: searchController,
|
controller: searchController,
|
||||||
onChanged: (value) => searchQuery.value = value,
|
onChanged: (value) => setState(() => searchQuery = value),
|
||||||
onFilterTap: () => _openFilterBottomSheet(context),
|
onFilterTap: _openFilterBottomSheet,
|
||||||
onRefreshTap: _refreshExpenses,
|
onRefreshTap: _refreshExpenses,
|
||||||
|
expenseController: expenseController,
|
||||||
|
),
|
||||||
|
_ToggleButtons(
|
||||||
|
isHistoryView: isHistoryView,
|
||||||
|
onToggle: (v) => setState(() => isHistoryView = v),
|
||||||
),
|
),
|
||||||
_ToggleButtons(isHistoryView: isHistoryView),
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Obx(() {
|
child: Obx(() {
|
||||||
if (expenseController.isLoading.value) {
|
if (expenseController.isLoading.value) {
|
||||||
return SkeletonLoaders.expenseListSkeletonLoader();
|
return SkeletonLoaders.expenseListSkeletonLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expenseController.errorMessage.isNotEmpty) {
|
if (expenseController.errorMessage.isNotEmpty) {
|
||||||
return Center(
|
return Center(
|
||||||
child: MyText.bodyMedium(
|
child: MyText.bodyMedium(
|
||||||
@ -80,39 +97,17 @@ class _ExpenseMainScreenState extends State<ExpenseMainScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expenseController.expenses.isEmpty) {
|
final listToShow = _getFilteredExpenses();
|
||||||
return Center(child: MyText.bodyMedium("No expenses found."));
|
return _ExpenseList(
|
||||||
}
|
expenseList: listToShow,
|
||||||
|
onViewDetail: () async {
|
||||||
final filteredList =
|
final result =
|
||||||
expenseController.expenses.where((expense) {
|
await Get.to(() => ExpenseDetailScreen(expenseId: listToShow.first.id));
|
||||||
final query = searchQuery.value.toLowerCase();
|
if (result == true) {
|
||||||
return query.isEmpty ||
|
expenseController.fetchExpenses();
|
||||||
expense.expensesType.name.toLowerCase().contains(query) ||
|
}
|
||||||
expense.supplerName.toLowerCase().contains(query) ||
|
},
|
||||||
expense.paymentMode.name.toLowerCase().contains(query);
|
);
|
||||||
}).toList();
|
|
||||||
|
|
||||||
// Sort by latest transaction date
|
|
||||||
filteredList.sort(
|
|
||||||
(a, b) => b.transactionDate.compareTo(a.transactionDate));
|
|
||||||
|
|
||||||
final now = DateTime.now();
|
|
||||||
final currentMonthList = filteredList
|
|
||||||
.where((e) =>
|
|
||||||
e.transactionDate.month == now.month &&
|
|
||||||
e.transactionDate.year == now.year)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
final historyList = filteredList
|
|
||||||
.where((e) => e.transactionDate
|
|
||||||
.isBefore(DateTime(now.year, now.month, 1)))
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
final listToShow =
|
|
||||||
isHistoryView.value ? historyList : currentMonthList;
|
|
||||||
|
|
||||||
return _ExpenseList(expenseList: listToShow);
|
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -130,7 +125,6 @@ class _ExpenseMainScreenState extends State<ExpenseMainScreen> {
|
|||||||
///---------------------- APP BAR ----------------------///
|
///---------------------- APP BAR ----------------------///
|
||||||
class _ExpenseAppBar extends StatelessWidget implements PreferredSizeWidget {
|
class _ExpenseAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||||
final ProjectController projectController;
|
final ProjectController projectController;
|
||||||
|
|
||||||
const _ExpenseAppBar({required this.projectController});
|
const _ExpenseAppBar({required this.projectController});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -138,63 +132,54 @@ class _ExpenseAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return PreferredSize(
|
return AppBar(
|
||||||
preferredSize: preferredSize,
|
backgroundColor: const Color(0xFFF5F5F5),
|
||||||
child: AppBar(
|
elevation: 0.5,
|
||||||
backgroundColor: const Color(0xFFF5F5F5),
|
automaticallyImplyLeading: false,
|
||||||
elevation: 0.5,
|
titleSpacing: 0,
|
||||||
automaticallyImplyLeading: false,
|
title: Padding(
|
||||||
titleSpacing: 0,
|
padding: MySpacing.xy(16, 0),
|
||||||
title: Padding(
|
child: Row(
|
||||||
padding: MySpacing.xy(16, 0),
|
children: [
|
||||||
child: Row(
|
IconButton(
|
||||||
children: [
|
icon: const Icon(Icons.arrow_back_ios_new, color: Colors.black, size: 20),
|
||||||
IconButton(
|
onPressed: () => Get.offNamed('/dashboard'),
|
||||||
icon: const Icon(Icons.arrow_back_ios_new,
|
),
|
||||||
color: Colors.black, size: 20),
|
MySpacing.width(8),
|
||||||
onPressed: () => Get.offNamed('/dashboard'),
|
Expanded(
|
||||||
),
|
child: Column(
|
||||||
MySpacing.width(8),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
Expanded(
|
mainAxisSize: MainAxisSize.min,
|
||||||
child: Column(
|
children: [
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
MyText.titleLarge(
|
||||||
mainAxisSize: MainAxisSize.min,
|
'Expenses',
|
||||||
children: [
|
fontWeight: 700,
|
||||||
MyText.titleLarge(
|
color: Colors.black,
|
||||||
'Expenses',
|
),
|
||||||
fontWeight: 700,
|
MySpacing.height(2),
|
||||||
color: Colors.black,
|
GetBuilder<ProjectController>(
|
||||||
),
|
builder: (_) {
|
||||||
MySpacing.height(2),
|
final projectName = projectController.selectedProject?.name ?? 'Select Project';
|
||||||
GetBuilder<ProjectController>(
|
return Row(
|
||||||
builder: (_) {
|
children: [
|
||||||
final projectName =
|
const Icon(Icons.work_outline, size: 14, color: Colors.grey),
|
||||||
projectController.selectedProject?.name ??
|
MySpacing.width(4),
|
||||||
'Select Project';
|
Expanded(
|
||||||
return InkWell(
|
child: MyText.bodySmall(
|
||||||
child: Row(
|
projectName,
|
||||||
children: [
|
fontWeight: 600,
|
||||||
const Icon(Icons.work_outline,
|
overflow: TextOverflow.ellipsis,
|
||||||
size: 14, color: Colors.grey),
|
color: Colors.grey[700],
|
||||||
MySpacing.width(4),
|
),
|
||||||
Expanded(
|
|
||||||
child: MyText.bodySmall(
|
|
||||||
projectName,
|
|
||||||
fontWeight: 600,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
color: Colors.grey[700],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
);
|
],
|
||||||
},
|
);
|
||||||
)
|
},
|
||||||
],
|
)
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -203,22 +188,22 @@ class _ExpenseAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
|
|
||||||
///---------------------- SEARCH AND FILTER ----------------------///
|
///---------------------- SEARCH AND FILTER ----------------------///
|
||||||
class _SearchAndFilter extends StatelessWidget {
|
class _SearchAndFilter extends StatelessWidget {
|
||||||
final TextEditingController searchController;
|
final TextEditingController controller;
|
||||||
final ValueChanged<String> onChanged;
|
final ValueChanged<String> onChanged;
|
||||||
final VoidCallback onFilterTap;
|
final VoidCallback onFilterTap;
|
||||||
final VoidCallback onRefreshTap;
|
final VoidCallback onRefreshTap;
|
||||||
|
final ExpenseController expenseController;
|
||||||
|
|
||||||
const _SearchAndFilter({
|
const _SearchAndFilter({
|
||||||
required this.searchController,
|
required this.controller,
|
||||||
required this.onChanged,
|
required this.onChanged,
|
||||||
required this.onFilterTap,
|
required this.onFilterTap,
|
||||||
required this.onRefreshTap,
|
required this.onRefreshTap,
|
||||||
|
required this.expenseController,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final ExpenseController expenseController = Get.find<ExpenseController>();
|
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: MySpacing.fromLTRB(12, 10, 12, 0),
|
padding: MySpacing.fromLTRB(12, 10, 12, 0),
|
||||||
child: Row(
|
child: Row(
|
||||||
@ -227,12 +212,11 @@ class _SearchAndFilter extends StatelessWidget {
|
|||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 35,
|
height: 35,
|
||||||
child: TextField(
|
child: TextField(
|
||||||
controller: searchController,
|
controller: controller,
|
||||||
onChanged: onChanged,
|
onChanged: onChanged,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12),
|
contentPadding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
prefixIcon:
|
prefixIcon: const Icon(Icons.search, size: 20, color: Colors.grey),
|
||||||
const Icon(Icons.search, size: 20, color: Colors.grey),
|
|
||||||
hintText: 'Search expenses...',
|
hintText: 'Search expenses...',
|
||||||
filled: true,
|
filled: true,
|
||||||
fillColor: Colors.white,
|
fillColor: Colors.white,
|
||||||
@ -298,46 +282,45 @@ class _SearchAndFilter extends StatelessWidget {
|
|||||||
|
|
||||||
///---------------------- TOGGLE BUTTONS ----------------------///
|
///---------------------- TOGGLE BUTTONS ----------------------///
|
||||||
class _ToggleButtons extends StatelessWidget {
|
class _ToggleButtons extends StatelessWidget {
|
||||||
final RxBool isHistoryView;
|
final bool isHistoryView;
|
||||||
|
final ValueChanged<bool> onToggle;
|
||||||
|
|
||||||
const _ToggleButtons({required this.isHistoryView});
|
const _ToggleButtons({required this.isHistoryView, required this.onToggle});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: MySpacing.fromLTRB(8, 12, 8, 5),
|
padding: MySpacing.fromLTRB(8, 12, 8, 5),
|
||||||
child: Obx(() {
|
child: Container(
|
||||||
return Container(
|
padding: const EdgeInsets.all(2),
|
||||||
padding: const EdgeInsets.all(2),
|
decoration: BoxDecoration(
|
||||||
decoration: BoxDecoration(
|
color: const Color(0xFFF0F0F0),
|
||||||
color: const Color(0xFFF0F0F0),
|
borderRadius: BorderRadius.circular(10),
|
||||||
borderRadius: BorderRadius.circular(10),
|
boxShadow: [
|
||||||
boxShadow: [
|
BoxShadow(
|
||||||
BoxShadow(
|
color: Colors.black.withOpacity(0.05),
|
||||||
color: Colors.black.withOpacity(0.05),
|
blurRadius: 4,
|
||||||
blurRadius: 4,
|
offset: const Offset(0, 2),
|
||||||
offset: const Offset(0, 2),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
child: Row(
|
||||||
child: Row(
|
children: [
|
||||||
children: [
|
_ToggleButton(
|
||||||
_ToggleButton(
|
label: 'Expenses',
|
||||||
label: 'Expenses',
|
icon: Icons.receipt_long,
|
||||||
icon: Icons.receipt_long,
|
selected: !isHistoryView,
|
||||||
selected: !isHistoryView.value,
|
onTap: () => onToggle(false),
|
||||||
onTap: () => isHistoryView.value = false,
|
),
|
||||||
),
|
_ToggleButton(
|
||||||
_ToggleButton(
|
label: 'History',
|
||||||
label: 'History',
|
icon: Icons.history,
|
||||||
icon: Icons.history,
|
selected: isHistoryView,
|
||||||
selected: isHistoryView.value,
|
onTap: () => onToggle(true),
|
||||||
onTap: () => isHistoryView.value = true,
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
);
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -370,8 +353,7 @@ class _ToggleButton extends StatelessWidget {
|
|||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Icon(icon,
|
Icon(icon, size: 16, color: selected ? Colors.white : Colors.grey),
|
||||||
size: 16, color: selected ? Colors.white : Colors.grey),
|
|
||||||
const SizedBox(width: 6),
|
const SizedBox(width: 6),
|
||||||
MyText.bodyMedium(
|
MyText.bodyMedium(
|
||||||
label,
|
label,
|
||||||
@ -389,38 +371,36 @@ class _ToggleButton extends StatelessWidget {
|
|||||||
///---------------------- EXPENSE LIST ----------------------///
|
///---------------------- EXPENSE LIST ----------------------///
|
||||||
class _ExpenseList extends StatelessWidget {
|
class _ExpenseList extends StatelessWidget {
|
||||||
final List<ExpenseModel> expenseList;
|
final List<ExpenseModel> expenseList;
|
||||||
|
final Future<void> Function()? onViewDetail;
|
||||||
|
|
||||||
const _ExpenseList({required this.expenseList});
|
const _ExpenseList({
|
||||||
|
required this.expenseList,
|
||||||
|
this.onViewDetail,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (expenseList.isEmpty) {
|
if (expenseList.isEmpty) {
|
||||||
return Center(child: MyText.bodyMedium('No expenses found.'));
|
return Center(child: MyText.bodyMedium('No expenses found.'));
|
||||||
}
|
}
|
||||||
final expenseController = Get.find<ExpenseController>();
|
|
||||||
return ListView.separated(
|
return ListView.separated(
|
||||||
padding: const EdgeInsets.fromLTRB(12, 12, 12, 80),
|
padding: const EdgeInsets.fromLTRB(12, 12, 12, 80),
|
||||||
itemCount: expenseList.length,
|
itemCount: expenseList.length,
|
||||||
separatorBuilder: (_, __) =>
|
separatorBuilder: (_, __) => Divider(color: Colors.grey.shade300, height: 20),
|
||||||
Divider(color: Colors.grey.shade300, height: 20),
|
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final expense = expenseList[index];
|
final expense = expenseList[index];
|
||||||
|
|
||||||
final formattedDate = DateTimeUtils.convertUtcToLocal(
|
final formattedDate = DateTimeUtils.convertUtcToLocal(
|
||||||
expense.transactionDate.toIso8601String(),
|
expense.transactionDate.toIso8601String(),
|
||||||
format: 'dd MMM yyyy, hh:mm a',
|
format: 'dd MMM yyyy, hh:mm a',
|
||||||
);
|
);
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
final result = await Get.to(
|
final result = await Get.to(
|
||||||
() => ExpenseDetailScreen(expenseId: expense.id),
|
() => ExpenseDetailScreen(expenseId: expense.id),
|
||||||
arguments: {'expense': expense},
|
arguments: {'expense': expense},
|
||||||
);
|
);
|
||||||
|
if (result == true && onViewDetail != null) {
|
||||||
// If status was updated, refresh expenses
|
await onViewDetail!();
|
||||||
if (result == true) {
|
|
||||||
expenseController.fetchExpenses();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
@ -431,28 +411,16 @@ class _ExpenseList extends StatelessWidget {
|
|||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
MyText.bodyMedium(
|
MyText.bodyMedium(expense.expensesType.name, fontWeight: 600),
|
||||||
expense.expensesType.name,
|
MyText.bodyMedium('₹ ${expense.amount.toStringAsFixed(2)}', fontWeight: 600),
|
||||||
fontWeight: 600,
|
|
||||||
),
|
|
||||||
MyText.bodyMedium(
|
|
||||||
'₹ ${expense.amount.toStringAsFixed(2)}',
|
|
||||||
fontWeight: 600,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 6),
|
const SizedBox(height: 6),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
MyText.bodySmall(
|
MyText.bodySmall(formattedDate, fontWeight: 500),
|
||||||
formattedDate,
|
|
||||||
fontWeight: 500,
|
|
||||||
),
|
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
MyText.bodySmall(
|
MyText.bodySmall(expense.status.name, fontWeight: 500),
|
||||||
expense.status.name,
|
|
||||||
fontWeight: 500,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -138,7 +138,7 @@ class _DailyProgressReportScreenState extends State<DailyProgressReportScreen>
|
|||||||
MySpacing.height(flexSpacing),
|
MySpacing.height(flexSpacing),
|
||||||
_buildActionBar(),
|
_buildActionBar(),
|
||||||
Padding(
|
Padding(
|
||||||
padding: MySpacing.x(flexSpacing),
|
padding: MySpacing.x(8),
|
||||||
child: _buildDailyProgressReportTab(),
|
child: _buildDailyProgressReportTab(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -158,7 +158,7 @@ class _DailyProgressReportScreenState extends State<DailyProgressReportScreen>
|
|||||||
children: [
|
children: [
|
||||||
_buildActionItem(
|
_buildActionItem(
|
||||||
label: "Filter",
|
label: "Filter",
|
||||||
icon: Icons.filter_list_alt,
|
icon: Icons.tune,
|
||||||
tooltip: 'Filter Project',
|
tooltip: 'Filter Project',
|
||||||
color: Colors.blueAccent,
|
color: Colors.blueAccent,
|
||||||
onTap: _openFilterSheet,
|
onTap: _openFilterSheet,
|
||||||
@ -318,7 +318,7 @@ class _DailyProgressReportScreenState extends State<DailyProgressReportScreen>
|
|||||||
..sort((a, b) => b.compareTo(a));
|
..sort((a, b) => b.compareTo(a));
|
||||||
|
|
||||||
return MyCard.bordered(
|
return MyCard.bordered(
|
||||||
borderRadiusAll: 4,
|
borderRadiusAll: 10,
|
||||||
border: Border.all(color: Colors.grey.withOpacity(0.2)),
|
border: Border.all(color: Colors.grey.withOpacity(0.2)),
|
||||||
shadow: MyShadow(elevation: 1, position: MyShadowPosition.bottom),
|
shadow: MyShadow(elevation: 1, position: MyShadowPosition.bottom),
|
||||||
paddingAll: 8,
|
paddingAll: 8,
|
||||||
|
@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:marco/helpers/theme/app_theme.dart';
|
import 'package:marco/helpers/theme/app_theme.dart';
|
||||||
import 'package:marco/helpers/utils/mixins/ui_mixin.dart';
|
import 'package:marco/helpers/utils/mixins/ui_mixin.dart';
|
||||||
import 'package:marco/helpers/utils/my_shadow.dart';
|
|
||||||
import 'package:marco/helpers/widgets/my_card.dart';
|
import 'package:marco/helpers/widgets/my_card.dart';
|
||||||
import 'package:marco/helpers/widgets/my_spacing.dart';
|
import 'package:marco/helpers/widgets/my_spacing.dart';
|
||||||
import 'package:marco/helpers/widgets/my_text.dart';
|
import 'package:marco/helpers/widgets/my_text.dart';
|
||||||
@ -160,7 +159,7 @@ class _DailyTaskPlaningScreenState extends State<DailyTaskPlaningScreen>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: MySpacing.x(flexSpacing),
|
padding: MySpacing.x(8),
|
||||||
child: dailyProgressReportTab(),
|
child: dailyProgressReportTab(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -232,10 +231,9 @@ class _DailyTaskPlaningScreenState extends State<DailyTaskPlaningScreen>
|
|||||||
final buildingKey = building.id.toString();
|
final buildingKey = building.id.toString();
|
||||||
|
|
||||||
return MyCard.bordered(
|
return MyCard.bordered(
|
||||||
borderRadiusAll: 12,
|
borderRadiusAll: 10,
|
||||||
paddingAll: 0,
|
paddingAll: 0,
|
||||||
margin: MySpacing.bottom(12),
|
margin: MySpacing.bottom(10),
|
||||||
shadow: MyShadow(elevation: 3),
|
|
||||||
child: Theme(
|
child: Theme(
|
||||||
data: Theme.of(context)
|
data: Theme.of(context)
|
||||||
.copyWith(dividerColor: Colors.transparent),
|
.copyWith(dividerColor: Colors.transparent),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user