refactor: Rename getButtonColor to getprimary and update related usages

This commit is contained in:
Vaibhav Surve 2025-11-04 15:18:12 +05:30
parent 5d99f3fdfd
commit 47da83813d
2 changed files with 41 additions and 68 deletions

View File

@ -95,7 +95,7 @@ class AttendanceButtonHelper {
} }
} }
static Color getButtonColor({ static Color getprimary({
required bool isYesterday, required bool isYesterday,
required bool isTodayApproved, required bool isTodayApproved,
required int activity, required int activity,

View File

@ -7,7 +7,6 @@ import 'package:marco/controller/attendance/attendance_screen_controller.dart';
import 'package:marco/helpers/utils/attendance_actions.dart'; import 'package:marco/helpers/utils/attendance_actions.dart';
import 'package:marco/controller/project_controller.dart'; import 'package:marco/controller/project_controller.dart';
import 'package:marco/helpers/utils/base_bottom_sheet.dart'; import 'package:marco/helpers/utils/base_bottom_sheet.dart';
import 'package:marco/helpers/widgets/my_text.dart';
class AttendanceActionButton extends StatefulWidget { class AttendanceActionButton extends StatefulWidget {
final dynamic employee; final dynamic employee;
@ -42,33 +41,26 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
}); });
} }
Future<DateTime?> _pickRegularizationTime(DateTime checkInTime) async { Future<DateTime?> _pickRegularizationTime(DateTime referenceTime) async {
final pickedTime = await showTimePicker( final pickedTime = await showTimePicker(
context: context, context: context,
initialTime: TimeOfDay.fromDateTime(DateTime.now()), initialTime:
TimeOfDay.fromDateTime(referenceTime), // start from actual log time
); );
if (pickedTime == null) return null; if (pickedTime == null) return null;
final selected = DateTime( final selected = DateTime(
checkInTime.year, referenceTime.year,
checkInTime.month, referenceTime.month,
checkInTime.day, referenceTime.day,
pickedTime.hour, pickedTime.hour,
pickedTime.minute, pickedTime.minute,
); );
final now = DateTime.now(); final now = DateTime.now();
if (selected.isBefore(checkInTime)) { // Allow times before check-in for regularization, but never future
showAppSnackbar(
title: "Invalid Time",
message: "Time must be after check-in.",
type: SnackbarType.warning,
);
return null;
}
if (selected.isAfter(now)) { if (selected.isAfter(now)) {
showAppSnackbar( showAppSnackbar(
title: "Invalid Time", title: "Invalid Time",
@ -85,8 +77,6 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
final controller = widget.attendanceController; final controller = widget.attendanceController;
final projectController = Get.find<ProjectController>(); final projectController = Get.find<ProjectController>();
final selectedProjectId = projectController.selectedProject?.id; final selectedProjectId = projectController.selectedProject?.id;
final projectName =
projectController.selectedProject?.name ?? 'Unknown Project';
if (selectedProjectId == null) { if (selectedProjectId == null) {
showAppSnackbar( showAppSnackbar(
@ -163,9 +153,7 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
actionText, actionText,
selectedTime: selectedTime, selectedTime: selectedTime,
checkInDate: widget.employee.checkIn, checkInDate: widget.employee.checkIn,
projectName: projectName,
); );
if (comment == null || comment.isEmpty) { if (comment == null || comment.isEmpty) {
controller.uploadingStates[uniqueLogKey]?.value = false; controller.uploadingStates[uniqueLogKey]?.value = false;
return; return;
@ -240,7 +228,7 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
isTodayApproved: isTodayApproved, isTodayApproved: isTodayApproved,
); );
final buttonColor = AttendanceButtonHelper.getButtonColor( final primary = AttendanceButtonHelper.getprimary(
isYesterday: isYesterday, isYesterday: isYesterday,
isTodayApproved: isTodayApproved, isTodayApproved: isTodayApproved,
activity: emp.activity, activity: emp.activity,
@ -250,7 +238,7 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
isUploading: isUploading, isUploading: isUploading,
isButtonDisabled: isButtonDisabled, isButtonDisabled: isButtonDisabled,
buttonText: buttonText, buttonText: buttonText,
buttonColor: buttonColor, primary: primary,
onPressed: isButtonDisabled ? null : _handleButtonPressed, onPressed: isButtonDisabled ? null : _handleButtonPressed,
); );
}); });
@ -261,7 +249,7 @@ class AttendanceActionButtonUI extends StatelessWidget {
final bool isUploading; final bool isUploading;
final bool isButtonDisabled; final bool isButtonDisabled;
final String buttonText; final String buttonText;
final Color buttonColor; final Color primary;
final VoidCallback? onPressed; final VoidCallback? onPressed;
const AttendanceActionButtonUI({ const AttendanceActionButtonUI({
@ -269,7 +257,7 @@ class AttendanceActionButtonUI extends StatelessWidget {
required this.isUploading, required this.isUploading,
required this.isButtonDisabled, required this.isButtonDisabled,
required this.buttonText, required this.buttonText,
required this.buttonColor, required this.primary,
required this.onPressed, required this.onPressed,
}); });
@ -280,17 +268,17 @@ class AttendanceActionButtonUI extends StatelessWidget {
child: ElevatedButton( child: ElevatedButton(
onPressed: onPressed, onPressed: onPressed,
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: buttonColor, backgroundColor: primary,
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 12), padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 12),
textStyle: const TextStyle(fontSize: 12), textStyle: const TextStyle(fontSize: 12),
), ),
child: isUploading child: isUploading
? const SizedBox( ? Container(
width: 16, width: 60,
height: 16, height: 14,
child: CircularProgressIndicator( decoration: BoxDecoration(
strokeWidth: 2, color: Colors.white.withOpacity(0.5),
valueColor: AlwaysStoppedAnimation<Color>(Colors.white), borderRadius: BorderRadius.circular(4),
), ),
) )
: Row( : Row(
@ -307,11 +295,10 @@ class AttendanceActionButtonUI extends StatelessWidget {
.contains(buttonText.toLowerCase())) .contains(buttonText.toLowerCase()))
const SizedBox(width: 4), const SizedBox(width: 4),
Flexible( Flexible(
child: MyText.bodySmall( child: Text(
buttonText, buttonText,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
fontWeight: 500, style: const TextStyle(fontSize: 12),
color: Colors.white,
), ),
), ),
], ],
@ -326,18 +313,15 @@ Future<String?> _showCommentBottomSheet(
String actionText, { String actionText, {
DateTime? selectedTime, DateTime? selectedTime,
DateTime? checkInDate, DateTime? checkInDate,
String? projectName,
}) async { }) async {
final commentController = TextEditingController(); final commentController = TextEditingController();
String? errorText; String? errorText;
String sheetTitle = // Prepare title
"Adding Comment for ${capitalizeFirstLetter(actionText)}"; String sheetTitle = "Add Comment for ${capitalizeFirstLetter(actionText)}";
if (selectedTime != null && checkInDate != null) { if (selectedTime != null && checkInDate != null) {
sheetTitle = sheetTitle =
"${capitalizeFirstLetter(actionText)}${DateFormat('dd MMM yyyy').format(checkInDate)} " "${capitalizeFirstLetter(actionText)} for ${DateFormat('dd MMM yyyy').format(checkInDate)} at ${DateFormat('hh:mm a').format(selectedTime)}";
"at ${DateFormat('hh:mm a').format(selectedTime)}\n"
"${projectName ?? 'Project'}";
} }
return showModalBottomSheet<String>( return showModalBottomSheet<String>(
@ -363,39 +347,28 @@ Future<String?> _showCommentBottomSheet(
padding: EdgeInsets.only( padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom), bottom: MediaQuery.of(context).viewInsets.bottom),
child: BaseBottomSheet( child: BaseBottomSheet(
title: sheetTitle, title: sheetTitle, // 👈 now showing full sentence as title
subtitle: projectName,
onCancel: () => Navigator.of(context).pop(), onCancel: () => Navigator.of(context).pop(),
onSubmit: submit, onSubmit: submit,
isSubmitting: false, isSubmitting: false,
submitText: 'Submit', submitText: 'Submit',
child: Column( child: TextField(
crossAxisAlignment: CrossAxisAlignment.start, controller: commentController,
children: [ maxLines: 4,
MyText.bodyMedium( decoration: InputDecoration(
'Add a comment to proceed', hintText: 'Type your comment here...',
fontWeight: 500, border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
), ),
const SizedBox(height: 8), filled: true,
TextField( fillColor: Colors.grey.shade100,
controller: commentController, errorText: errorText,
maxLines: 4, ),
decoration: InputDecoration( onChanged: (_) {
hintText: 'Type your comment here...', if (errorText != null) {
border: OutlineInputBorder( setModalState(() => errorText = null);
borderRadius: BorderRadius.circular(8), }
), },
filled: true,
fillColor: Colors.grey.shade100,
errorText: errorText,
),
onChanged: (_) {
if (errorText != null) {
setModalState(() => errorText = null);
}
},
),
],
), ),
), ),
); );