- Replaced instances of the Logger package with a custom appLogger for consistent logging. - Introduced app_logger.dart to manage logging with file output and storage permissions. - Updated all controllers (e.g., DashboardController, EmployeesScreenController, etc.) to use appLogger for logging messages. - Ensured that logging messages are appropriately categorized (info, warning, error) throughout the application. - Implemented a file logging mechanism to store logs in a designated directory. - Cleaned up old log files to maintain only the most recent logs.
292 lines
12 KiB
Dart
292 lines
12 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:marco/controller/task_planing/add_task_controller.dart';
|
|
import 'package:marco/helpers/widgets/my_text.dart';
|
|
|
|
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
|
|
|
|
|
|
|
void showCreateTaskBottomSheet({
|
|
required String workArea,
|
|
required String activity,
|
|
required String completedWork,
|
|
required String unit,
|
|
required Function(String) onCategoryChanged,
|
|
required String parentTaskId,
|
|
required int plannedTask,
|
|
required String activityId,
|
|
required String workAreaId,
|
|
required VoidCallback onSubmit,
|
|
}) {
|
|
final controller = Get.put(AddTaskController());
|
|
final TextEditingController plannedTaskController =
|
|
TextEditingController(text: plannedTask.toString());
|
|
final TextEditingController descriptionController = TextEditingController();
|
|
|
|
Get.bottomSheet(
|
|
StatefulBuilder(
|
|
builder: (context, setState) {
|
|
return LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final isLarge = constraints.maxWidth > 600;
|
|
final horizontalPadding =
|
|
isLarge ? constraints.maxWidth * 0.2 : 16.0;
|
|
|
|
return // Inside showManageTaskBottomSheet...
|
|
|
|
SafeArea(
|
|
child: Material(
|
|
color: Colors.white,
|
|
borderRadius:
|
|
const BorderRadius.vertical(top: Radius.circular(20)),
|
|
child: Container(
|
|
constraints: const BoxConstraints(maxHeight: 760),
|
|
padding: EdgeInsets.fromLTRB(
|
|
horizontalPadding, 12, horizontalPadding, 24),
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Center(
|
|
child: Container(
|
|
width: 40,
|
|
height: 4,
|
|
margin: const EdgeInsets.only(bottom: 16),
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey.shade400,
|
|
borderRadius: BorderRadius.circular(2),
|
|
),
|
|
),
|
|
),
|
|
Center(
|
|
child: MyText.titleLarge(
|
|
"Create Task",
|
|
fontWeight: 700,
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
_infoCardSection([
|
|
_infoRowWithIcon(
|
|
Icons.workspaces, "Selected Work Area", workArea),
|
|
_infoRowWithIcon(
|
|
Icons.list_alt, "Selected Activity", activity),
|
|
_infoRowWithIcon(Icons.check_circle_outline,
|
|
"Completed Work", completedWork),
|
|
]),
|
|
const SizedBox(height: 16),
|
|
_sectionTitle(Icons.edit_calendar, "Planned Work"),
|
|
const SizedBox(height: 6),
|
|
_customTextField(
|
|
controller: plannedTaskController,
|
|
hint: "Enter planned work",
|
|
keyboardType: TextInputType.number,
|
|
),
|
|
const SizedBox(height: 16),
|
|
_sectionTitle(Icons.description_outlined, "Comment"),
|
|
const SizedBox(height: 6),
|
|
_customTextField(
|
|
controller: descriptionController,
|
|
hint: "Enter task description",
|
|
maxLines: 3,
|
|
),
|
|
const SizedBox(height: 16),
|
|
_sectionTitle(
|
|
Icons.category_outlined, "Selected Work Category"),
|
|
const SizedBox(height: 6),
|
|
Obx(() {
|
|
final categoryMap = controller.categoryIdNameMap;
|
|
final String selectedName =
|
|
controller.selectedCategoryId.value != null
|
|
? (categoryMap[controller
|
|
.selectedCategoryId.value!] ??
|
|
'Select Category')
|
|
: 'Select Category';
|
|
|
|
return Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 12, vertical: 14),
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey.shade100,
|
|
border: Border.all(color: Colors.grey.shade300),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: PopupMenuButton<String>(
|
|
padding: EdgeInsets.zero,
|
|
onSelected: (val) {
|
|
controller.selectCategory(val);
|
|
onCategoryChanged(val);
|
|
},
|
|
itemBuilder: (context) => categoryMap.entries
|
|
.map(
|
|
(entry) => PopupMenuItem<String>(
|
|
value: entry.key,
|
|
child: Text(entry.value),
|
|
),
|
|
)
|
|
.toList(),
|
|
child: Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
selectedName,
|
|
style: const TextStyle(
|
|
fontSize: 14, color: Colors.black87),
|
|
),
|
|
const Icon(Icons.arrow_drop_down),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}),
|
|
const SizedBox(height: 24),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: OutlinedButton.icon(
|
|
onPressed: () => Get.back(),
|
|
icon: const Icon(Icons.close, size: 18),
|
|
label: MyText.bodyMedium("Cancel",
|
|
fontWeight: 600),
|
|
style: OutlinedButton.styleFrom(
|
|
side: const BorderSide(color: Colors.grey),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(10)),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: ElevatedButton.icon(
|
|
onPressed: () async {
|
|
final plannedValue = int.tryParse(
|
|
plannedTaskController.text.trim()) ??
|
|
0;
|
|
final comment =
|
|
descriptionController.text.trim();
|
|
final selectedCategoryId =
|
|
controller.selectedCategoryId.value;
|
|
if (selectedCategoryId == null) {
|
|
showAppSnackbar(
|
|
title: "error",
|
|
message: "Please select a work category!",
|
|
type: SnackbarType.error,
|
|
);
|
|
return;
|
|
}
|
|
|
|
final success = await controller.createTask(
|
|
parentTaskId: parentTaskId,
|
|
plannedTask: plannedValue,
|
|
comment: comment,
|
|
workAreaId: workAreaId,
|
|
activityId: activityId,
|
|
categoryId: selectedCategoryId,
|
|
);
|
|
|
|
if (success) {
|
|
Get.back();
|
|
Future.delayed(
|
|
const Duration(milliseconds: 300), () {
|
|
onSubmit();
|
|
showAppSnackbar(
|
|
title: "Success",
|
|
message: "Task created successfully!",
|
|
type: SnackbarType.success,
|
|
);
|
|
});
|
|
}
|
|
},
|
|
icon: const Icon(Icons.check, size: 18),
|
|
label: MyText.bodyMedium("Submit",
|
|
color: Colors.white, fontWeight: 600),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.blueAccent,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(10)),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
isScrollControlled: true,
|
|
);
|
|
}
|
|
|
|
Widget _sectionTitle(IconData icon, String title) {
|
|
return Row(
|
|
children: [
|
|
Icon(icon, color: Colors.grey[700], size: 18),
|
|
const SizedBox(width: 8),
|
|
MyText.bodyMedium(title, fontWeight: 600),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _customTextField({
|
|
required TextEditingController controller,
|
|
required String hint,
|
|
int maxLines = 1,
|
|
TextInputType keyboardType = TextInputType.text,
|
|
}) {
|
|
return TextField(
|
|
controller: controller,
|
|
maxLines: maxLines,
|
|
keyboardType: keyboardType,
|
|
decoration: InputDecoration(
|
|
hintText: hint,
|
|
filled: true,
|
|
fillColor: Colors.grey.shade100,
|
|
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _infoCardSection(List<Widget> children) {
|
|
return Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey.shade100,
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(color: Colors.grey.shade300),
|
|
),
|
|
child: Column(children: children),
|
|
);
|
|
}
|
|
|
|
Widget _infoRowWithIcon(IconData icon, String title, String value) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 6),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Icon(icon, color: Colors.grey[700], size: 18),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
MyText.bodyMedium(title, fontWeight: 600),
|
|
const SizedBox(height: 2),
|
|
MyText.bodySmall(value, color: Colors.grey[800]),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|