DatePicker class

A picker control that lets users select a date.

The date picker provides a standardized way for users to pick a localized date value using touch, mouse, or keyboard input. It displays separate fields for month, day, and year that expand into scrollable lists.

DatePicker Preview

{@tool snippet} This example shows a basic date picker:

DatePicker(
  selected: selectedDate,
  onChanged: (date) => setState(() => selectedDate = date),
  header: 'Select a date',
)

{@end-tool}

{@tool snippet} This example shows a date picker with restricted range:

DatePicker(
  selected: selectedDate,
  onChanged: (date) => setState(() => selectedDate = date),
  startDate: DateTime(2020, 1, 1),
  endDate: DateTime(2025, 12, 31),
)

{@end-tool}

Field configuration

Use showMonth, showDay, and showYear to show or hide specific fields. Use fieldOrder to customize the order of fields based on locale.

See also:

Inheritance

Constructors

DatePicker({required DateTime? selected, Key? key, ValueChanged<DateTime>? onChanged, VoidCallback? onCancel, String? header, TextStyle? headerStyle, bool showDay = true, bool showMonth = true, bool showYear = true, DateTime? startDate, DateTime? endDate, EdgeInsetsGeometry contentPadding = kPickerContentPadding, double popupHeight = kPickerPopupHeight, FocusNode? focusNode, bool autofocus = false, Locale? locale, List<DatePickerField>? fieldOrder, List<int>? fieldFlex})
Creates a date picker.

Properties

autofocus → bool
True if this widget will be selected as the initial focus when no other node in its scope is currently focused.
final
contentPadding → EdgeInsetsGeometry
The padding of the picker fields. Defaults to kPickerContentPadding
final
endDate → DateTime
The date displayed at the end of the list
final
fieldFlex → List<int>?
The flex of the fields.
final
fieldOrder → List<DatePickerField>?
The order of the fields.
final
focusNode → FocusNode?
An optional focus node to use as the focus node for this widget.
final
hashCode → int
The hash code for this object.
no setterinherited
The content of the header
final
headerStyle → TextStyle?
The style of the header
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
locale → Locale?
The locale used to format the month name.
final
onCancel → VoidCallback?
Called when the user cancels the picker.
final
onChanged → ValueChanged<DateTime>?
Whenever the current selected date is changed by the user.
final
popupHeight → double
The height of the popup.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
selected → DateTime?
The current date selected date.
final
showDay → bool
Whenever to show the day field
final
showMonth → bool
Whenever to show the month field
final
showYear → bool
Whenever to show the year field
final
startDate → DateTime
The date displayed at the beggining
final

Methods

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → State<DatePicker>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited