working hours issue fixed
parent
f45e0e4f80
commit
010aaf9fe2
@ -1,25 +1,23 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ServiceRequestUtils{
|
||||
static int calculateAndAssignWorkingHours({
|
||||
class ServiceRequestUtils {
|
||||
static double calculateAndAssignWorkingHours({
|
||||
required DateTime? startTime,
|
||||
required DateTime? endTime,
|
||||
required TextEditingController workingHoursController,
|
||||
required Function(int) updateModel, // A callback to update the model
|
||||
required Function(double) updateModel, // A callback to update the model
|
||||
}) {
|
||||
print('end date i got is ${endTime}');
|
||||
print('start date i got is $startTime');
|
||||
print('end date i got is $endTime');
|
||||
if (startTime != null && endTime != null) {
|
||||
|
||||
Duration difference = endTime.difference(startTime);
|
||||
int hours = difference.inHours;
|
||||
|
||||
// Update the controller and model
|
||||
workingHoursController.text = hours.toString();
|
||||
double hours = difference.inMinutes / 60.0; // Calculate hours as a decimal
|
||||
workingHoursController.text = hours.toStringAsFixed(1); // Format to 1 decimal places
|
||||
updateModel(hours); // Call the function to update the model
|
||||
|
||||
return hours;
|
||||
} else {
|
||||
return -1; // Indicating invalid input
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue