[Fluth]showDataPickerの特定の日付を無効にする


showDataPickerの特定の日付を無効にする


仕事中はDatePickerで特定の日付を選びたい
このコードを適用します.

showDataPickerパラメータ

Future<DateTime?> showDatePicker({
  required BuildContext context,
  required DateTime initialDate,
  required DateTime firstDate,
  required DateTime lastDate,
  DateTime? currentDate,
  DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
  SelectableDayPredicate? selectableDayPredicate,
  String? helpText,
  String? cancelText,
  String? confirmText,
  Locale? locale,
  bool useRootNavigator = true,
  RouteSettings? routeSettings,
  TextDirection? textDirection,
  TransitionBuilder? builder,
  DatePickerMode initialDatePickerMode = DatePickerMode.day,
  String? errorFormatText,
  String? errorInvalidText,
  String? fieldHintText,
  String? fieldLabelText,
})
2つの特定の日付を無効にするパラメータはselectableDayPredicateです.
selectableDayPredicate: (각 항목의 날짜) {
  //true: selectable
  //false: unSelectable
  return booltype;
}

Future<DateTime?> selectedDate = showDatePicker(
  context: Get.context!,
  initialDate: DateTime.now(),
  firstDate: DateTime.now(),
  lastDate: DateTime.utc(2025, 12, 31),
  selectableDayPredicate: (date) {
     //2022년 3월 31일만 비활성화
    if (date == DateTime(2022, 3, 31))
      return false;
    else
      return true;
    }
);

3月31日に無効になりました.
28日前日に無効になった理由:firstDateDateTime.now()に設定されており、今日から選択可能