showCustomDateRangePicker static method

Future<DateTimeRange?> showCustomDateRangePicker({
  1. DateTimeRange? initialDateRange,
  2. DateTime? firstDate,
  3. DateTime? lastDate,
  4. String? helpText,
  5. String? cancelText,
  6. String? confirmText,
  7. String? saveText,
  8. Color? primaryColor,
  9. Color? textColor,
  10. Color? backgroundColor,
  11. bool barrierDismissible = true,
})

Implementation

static Future<DateTimeRange?> showCustomDateRangePicker({
  DateTimeRange? initialDateRange,
  DateTime? firstDate,
  DateTime? lastDate,
  String? helpText,
  String? cancelText,
  String? confirmText,
  String? saveText,
  Color? primaryColor,
  Color? textColor,
  Color? backgroundColor,
  bool barrierDismissible = true,
}) async {
  firstDate ??= DateTime(1900);
  lastDate ??= DateTime(2100);
  primaryColor ??= AppColors.primary;
  backgroundColor ??= Colors.white;
  textColor ??= AppColors.text;

  initialDateRange ??= DateTimeRange(
    start: DateTime.now(),
    end: DateTime.now().add(const Duration(days: 7)),
  );

  return await showDateRangePicker(
    context: Get.context!,
    initialDateRange: initialDateRange,
    firstDate: firstDate,
    lastDate: lastDate,
    helpText: helpText,
    cancelText: cancelText,
    confirmText: confirmText,
    saveText: saveText,
    builder: (context, child) {
      return Theme(
        data: Theme.of(context).copyWith(
          colorScheme: ColorScheme.light(
            primary: primaryColor ?? AppColors.primary,
            onPrimary: Colors.white,
            onSurface: textColor ?? AppColors.text,
            surface: backgroundColor ?? Colors.white,
          ),
          textButtonTheme: TextButtonThemeData(
            style: TextButton.styleFrom(
              foregroundColor: primaryColor,
              textStyle: AppTextThemes.button(),
            ),
          ),
          dialogBackgroundColor: backgroundColor,
          datePickerTheme: DatePickerThemeData(
            backgroundColor: backgroundColor,
            headerBackgroundColor: primaryColor,
            headerForegroundColor: Colors.white,
            surfaceTintColor: backgroundColor,
            dayBackgroundColor: WidgetStateProperty.resolveWith((states) {
              if (states.contains(WidgetState.selected)) {
                return primaryColor;
              }
              return null;
            }),
            dayForegroundColor: WidgetStateProperty.resolveWith((states) {
              if (states.contains(WidgetState.selected)) {
                return Colors.white;
              }
              return textColor;
            }),
            todayBackgroundColor: WidgetStateProperty.resolveWith((states) {
              if (states.contains(WidgetState.selected)) {
                return primaryColor;
              }
              return (primaryColor ?? AppColors.primary).withOpacity(0.2);
            }),
            todayForegroundColor: WidgetStateProperty.resolveWith((states) {
              if (states.contains(WidgetState.selected)) {
                return Colors.white;
              }
              return primaryColor;
            }),
          ),
        ),
        child: child!,
      );
    },
    barrierDismissible: barrierDismissible,
  );
}