selectTime method

Future<TimeOfDay?> selectTime({
  1. TimeOfDay? initialTime,
})

Implementation

Future<TimeOfDay?> selectTime({TimeOfDay? initialTime}) async {
  return await showTimePicker(
    context: Get.context!,
    initialTime: initialTime ?? TimeOfDay.now(),
    builder: (BuildContext context, Widget? child) {
      return MediaQuery(
        data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: false), // Ensure AM/PM format
        child: Theme(
          data: Theme.of(context).copyWith(
            colorScheme: ColorScheme.light(
              primary: AppTheme.themeColors.primary, // Header background color
              onPrimary: AppTheme.themeColors.tertiary, // Header text color
              onSurface: AppTheme.themeColors.text, // Body text color
            ),
            textButtonTheme: TextButtonThemeData(
              style: TextButton.styleFrom(
                foregroundColor: AppTheme.themeColors.primary, // Button text color
              ),
            ),
            timePickerTheme: TimePickerThemeData(
              dialBackgroundColor: AppTheme.themeColors.primary.withAlpha(10), // Dial background color
              dialHandColor: AppTheme.themeColors.primary, // Dial hand color
              dayPeriodTextColor: WidgetStateColor.resolveWith((states) {
                // Customize AM/PM text colors
                if (states.contains(WidgetState.selected)) {
                  return AppTheme.themeColors.tertiary; // Selected text color
                }
                return AppTheme.themeColors.primary; // Default text color
              }),
              dayPeriodColor: WidgetStateColor.resolveWith((states) {
                // Customize AM/PM button background color
                if (states.contains(WidgetState.selected)) {
                  return AppTheme.themeColors.primary; // Selected background color
                }
                return AppTheme.themeColors.base; // Default background color
              }),
            ), dialogTheme: DialogThemeData(backgroundColor: AppTheme.themeColors.darkGray),
          ),

          child: child!,
        ),
      );
    },
  );
}