You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
class ServiceRequestUtils {
|
|
|
|
|
static double calculateAndAssignWorkingHours({
|
|
|
|
|
required DateTime? startTime,
|
|
|
|
|
required DateTime? endTime,
|
|
|
|
|
required TextEditingController workingHoursController,
|
|
|
|
|
required Function(double) updateModel, // A callback to update the model
|
|
|
|
|
}) {
|
|
|
|
|
print('start date i got is $startTime');
|
|
|
|
|
print('end date i got is $endTime');
|
|
|
|
|
if (startTime != null && endTime != null) {
|
|
|
|
|
Duration difference = endTime.difference(startTime);
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|