Date Picker
A date picker allows a date to be selected from a calendar or input field.
It is recommended to use FDatePicker.calendar on touch devices and FDatePicker.new/FDatePicker.input on non-primarily touch devices.
The input field supports both arrow key navigation:
- Up/Down arrows: Increment/decrement values
- Left/Right arrows: Move between date segments
The input field does not support the following locales that use non-western numerals, it will default to English (United States):
- Arabic (العربية)
- Bengali (বাংলা)
- Persian/Farsi (فارسی)
- Burmese (မြန်မာ)
- Nepali (नेपाली)
- Pashto (پښتو)
Usage
FDatePicker(...)
FDatePicker(
controller: FDatePickerController(
vsync: this,
initialDate: DateTime(2024, 1, 1),
validator: (date) => date?.isBefore(DateTime.now()) ?? false ? 'Date must be in the future' : null,
),
style: FDatePickerStyle(),
textAlign: TextAlign.start,
textAlignVertical: TextAlignVertical.center,
autofocus: false,
expands: false,
onEditingComplete: () => print('Editing complete'),
onSubmit: (date) => print('Date submitted: $date'),
mouseCursor: SystemMouseCursors.text,
canRequestFocus: true,
baselineInputYear: 2000,
prefixBuilder: (context, styles, child) => Icon(Icons.calendar_today),
suffixBuilder: null,
calendar: FDatePickerCalendarProperties(),
label: Text('Select Date'),
description: Text('Choose a date from the calendar or input field'),
enabled: true,
onSaved: (date) => print('Date saved: $date'),
autovalidateMode: AutovalidateMode.onUnfocus,
);
FDatePicker.calendar(...)
FDatePicker.calendar(
controller: FDatePickerController(
vsync: this,
initialDate: DateTime(2024, 1, 1),
),
format: DateFormat('d MMM y'),
textAlign: TextAlign.start,
textAlignVertical: TextAlignVertical.center,
expands: false,
mouseCursor: SystemMouseCursors.text,
canRequestFocus: true,
hint: 'Select a date',
start: DateTime(2024),
end: DateTime(2025),
today: DateTime.now(),
initialType: FCalendarPickerType.yearMonth,
autoHide: true,
anchor: Alignment.topLeft,
inputAnchor: Alignment.bottomLeft,
directionPadding: false,
label: Text('Calendar Date'),
description: Text('Select a date from the calendar'),
prefixBuilder: (context, styles, child) => Icon(Icons.calendar_today),
suffixBuilder: null,
);
FDatePicker.input(...)
FDatePicker.input(
controller: FDatePickerController(
vsync: this,
initialDate: DateTime(2024, 1, 1),
),
textInputAction: TextInputAction.done,
textAlign: TextAlign.start,
textAlignVertical: TextAlignVertical.center,
expands: false,
onEditingComplete: () => print('Editing complete'),
onSubmit: (date) => print('Date submitted: $date'),
mouseCursor: SystemMouseCursors.text,
canRequestFocus: true,
baselineInputYear: 2000,
label: Text('Input Date'),
description: Text('Enter a date using the keyboard'),
autovalidateMode: AutovalidateMode.onUnfocus,
prefixBuilder: (context, styles, child) => Icon(Icons.calendar_today),
suffixBuilder: null,
)