import 'package:device_calendar/device_calendar.dart'; import 'package:flutter/material.dart'; import 'package:flutter_timezone/flutter_timezone.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:test_sa/controllers/notification/notification_manger.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 } } static String calculateTimeDifference(DateTime startDate, DateTime endDate) { Duration diff = endDate.difference(startDate); int days = diff.inDays; int hours = diff.inHours.remainder(24); int minutes = diff.inMinutes.remainder(60); int seconds = diff.inSeconds.remainder(60); List parts = []; if (days > 0) parts.add('$days ${days == 1 ? 'day' : 'days'}'); if (hours > 0) parts.add('$hours ${hours == 1 ? 'hour' : 'hours'}'); if (minutes > 0) parts.add('$minutes ${minutes == 1 ? 'minute' : 'minutes'}'); if (seconds > 0) parts.add('$seconds ${seconds == 1 ? 'second' : 'seconds'}'); String timeDifference = parts.isEmpty ? '' : parts.join(', '); return 'Action duration: $timeDifference'; } static Widget testScheduleNotificationButton({required BuildContext context}){ return ElevatedButton( child: const Text('Schedule notifications'), onPressed: () { // debugPrint('Notification Scheduled for $D'); // NotificationManger.showNotification(context: context, title: 'test notification', subtext: 'test notification', hashcode: 1); DateTime scheduleTime= DateTime.now().add(const Duration(seconds: 10)); NotificationManger.scheduleNotification( title: 'Scheduled Notification', body: '$scheduleTime', scheduledNotificationDateTime: scheduleTime);(); }, ); } //steps: //add permission for andriod.. //add string in info.plist for ios... //create event.. static Widget testAddEventToCalendarButton({required BuildContext context}){ return ElevatedButton( child: const Text('Add Event to Calendar'), onPressed: () async { var currentLocation = getLocation( await FlutterTimezone.getLocalTimezone()); setLocalLocation(currentLocation); await Future.delayed(const Duration(seconds: 2)); var eventToCreate = Event( "1", title: "test123", description: "test", start: TZDateTime.now(currentLocation), end: TZDateTime.now(currentLocation).add(const Duration(seconds: 10)), ); final createEventResult = await DeviceCalendarPlugin().createOrUpdateEvent(eventToCreate); if (createEventResult!.isSuccess) { Fluttertoast.showToast(msg: 'added successfully'); } }, ); } }