I want to disable the current date in showDatePicker. I was able to disable the past date in the showDatePicker but i also want to disable the current date in showDatePicker
here is my code:
showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime.now()
.subtract(Duration(days: 0)),
lastDate: DateTime(2025),
// selectableDayPredicate:
// _decideWhichDayToEnable,
);
i have updated, user can still press the 24 but i want it to be disable..
intialDate property is the key here.
DateTime intialDate = DateTime.now().add(Duration(days: 1));
showDatePicker(
context: context,
initialDate: intialDate,
initialDatePickerMode: DatePickerMode.day,
firstDate: intialDate,
lastDate: DateTime(2025));
This is the output am getting.
From your code what I understand is that you have to set Tomorrow as the firstDate and inialDate. You just need to set those values like DateTime.now().add(const Duration(days: 1)). I hope that will work.
Related
I have built a custome scrollable date picker in the flutter and i dont know how to limit the display of the dateenter image description herecode of date pickerDate picker
I want the program to diplay upto 7 date from the current date.
There is no need for a custom Date Picker, just use the built-in one:
DateTime? dateTime = showDatePicker(
initialDate: DateTime.now(),
firstDate: DateTime.now(),
lastDate: DateTime.now().add(Duration(days: 7)),
(...)
Here, you can set the bouds yourself. This is an example for the time range now-in 7 days
How can we allow only selection of 30 days with any start date in DateRangePicker?
Only firstDate and lastDate can be provided, which can be restricted to 30 days starting from the provided firstDate only.
final picked = await showDateRangePicker(
context: context,
firstDate: (DateTime.now()).subtract(Duration(days: 30)),
lastDate: DateTime.now(),
currentDate: DateTime.now(),
saveText: 'Done',
);
I want the user to select only 1st of every month when they click on the date picker. Currently, I'm able to show the date picker to select a date only if the current date is 1st using selectableDayPredicate if the current date is not the 1st of that month the date picker will not open. I want the date picker to open even if the current date is not the 1st of that month and all the other dates should be disabled and can select a different month's 1st date.
Here is the code:
Future<void> _selectDate(BuildContext context) async {
final DateTime? picked = await showDatePicker(
context: context,
initialDate: selectedDate,
firstDate: DateTime(2015, 8),
lastDate: DateTime(2101),
selectableDayPredicate: (day) => day.day == 1 ? true : false,
);
}
here is the code that you need:
final DateTime? picked = await showDatePicker
(
context: context,
initialDate: DateTime(DateTime.now().year,DateTime.now().month,1),
firstDate: DateTime(2015, 8),
lastDate: DateTime(2101),
selectableDayPredicate: (day) => day.day == 1 ? true : false,
);
you should initialDate to the first day of every month and because of this it selects the first day of the month that you are in. and your conditions works in this way because you are sure that you are not disabling the first days that you have initialized.
happy coding...
I changed the initial date to 1st of the month. It's working
i use package table calendar, how to disable table calendar past day on flutter
if on week view hide all past day
on mont view grey all past day on this month and disable to past month
enter image description here
showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime.now(),
lastDate: DateTime(DateTime.now().year + 5),
),
In Flutter, I use showDatePicker method to show the date picker, but how to open date picker that show/open the year selection by default, before going to select month & date?
Set the property initialDatePickerMode to DatePickerMode.year (doc)
Code Sample:
showDatePicker(
context: context,
initialDatePickerMode: DatePickerMode.year,
initialDate: initialDate,
firstDate: DateTime(firstDate),
lastDate: DateTime(lastDate),
);