Orientação gerada a partir de informações públicas. Apenas para referência.
Um pacote Flutter que fornece um seletor de data com estilo iOS compatível com Android e outras plataformas. Ele replica a aparência e o comportamento do seletor nativo Cupertino, garantindo uma experiência consistente para o usuário em diferentes dispositivos. O fork mantém compatibilidade com versões modernas do Flutter e suporta múltiplas plataformas, incluindo Web, macOS, Windows e Linux. Ideal para aplicativos que buscam oferecer uma aparência nativa do iOS sem código específico da plataforma.
Casos de uso
Seleção de data do estilo iOS em aplicativos multiplataforma
interface de seleção de data consistente entre Android e iOS
entrada de data semelhante à nativa em aplicativos web e desktop
/// Display date picker in bottom sheet.////// context: [BuildContext]/// minDateTime: [DateTime] minimum date time/// maxDateTime: [DateTime] maximum date time/// initialDateTime: [DateTime] initial date time for selected/// dateFormat: [String] date format pattern/// locale: [DateTimePickerLocale] internationalization/// pickerMode: [DateTimePickerMode] display mode: date(DatePicker)、time(TimePicker)、datetime(DateTimePicker)/// pickerTheme: [DateTimePickerTheme] the theme of date time picker/// onCancel: [DateVoidCallback] pressed title cancel widget event/// onClose: [DateVoidCallback] date picker closed event/// onChange: [DateValueCallback] selected date time changed event/// onConfirm: [DateValueCallback] pressed title confirm widget eventDatePicker.showDatePicker(
context,
minDateTime: DateTime(2019, 1, 1),
maxDateTime: DateTime(2021, 12, 31),
initialDateTime: DateTime(2020, 6, 15),
dateFormat: 'yyyy-MMMM-dd',
locale: DateTimePickerLocale.en_us,
pickerMode: DateTimePickerMode.date,
pickerTheme: DateTimePickerTheme.Default,
minuteDivider: 1,
onMonthChangeStartWithFirstDate: false,
onCancel: () => print('cancel'),
onClose: () => print('close'),
onChange: (dateTime, index) => print('$dateTime'),
onConfirm: (dateTime, index) => print('$dateTime'),
);
DatePicker Widget
/// Display date picker widget.////// minDateTime: [DateTime] minimum date time/// maxDateTime: [DateTime] maximum date time/// initialDateTime: [DateTime] initial date time for selected/// dateFormat: [String] date format pattern/// locale: [DateTimePickerLocale] internationalization/// pickerTheme: [DateTimePickerTheme] the theme of date time picker/// onCancel: [DateVoidCallback] pressed title cancel widget event/// onChange: [DateValueCallback] selected date time changed event/// onConfirm: [DateValueCallback] pressed title confirm widget eventDatePickerWidget(
minDateTime: DateTime(2019, 1, 1),
maxDateTime: DateTime(2021, 12, 31),
initialDateTime: DateTime(2020, 6, 15),
dateFormat: 'yyyy-MMMM-dd',
locale: DateTimePickerLocale.en_us,
pickerTheme: DateTimePickerTheme.Default,
onChange: (dateTime, selectedIndex) { },
onConfirm: (dateTime, selectedIndex) { },
)
TimePicker Widget
/// Display time picker widget.////// minDateTime: [DateTime] minimum date time/// maxDateTime: [DateTime] maximum date time/// initialDateTime: [DateTime] initial date time for selected/// dateFormat: [String] date format pattern/// locale: [DateTimePickerLocale] internationalization/// pickerTheme: [DateTimePickerTheme] the theme of date time picker/// minuteDivider: [int] minute restriction, e.g. 5: every 5th minute will be shown (0, 5, 10, 15 ...)/// onCancel: [DateVoidCallback] pressed title cancel widget event/// onChange: [DateValueCallback] selected date time changed event/// onConfirm: [DateValueCallback] pressed title confirm widget eventTimePickerWidget(
minDateTime: DateTime(2019, 1, 1, 8, 0),
maxDateTime: DateTime(2021, 12, 31, 22, 0),
initDateTime: DateTime(2020, 6, 15, 14, 30),
dateFormat: 'HH:mm',
locale: DateTimePickerLocale.en_us,
pickerTheme: DateTimePickerTheme.Default,
minuteDivider: 1,
onChange: (dateTime, selectedIndex) { },
onConfirm: (dateTime, selectedIndex) { },
)
DateTimePicker Widget
/// Display date time picker widget.////// minDateTime: [DateTime] minimum date time/// maxDateTime: [DateTime] maximum date time/// initialDateTime: [DateTime] initial date time for selected/// dateFormat: [String] date format pattern/// locale: [DateTimePickerLocale] internationalization/// pickerTheme: [DateTimePickerTheme] the theme of date time picker/// onCancel: [DateVoidCallback] pressed title cancel widget event/// onChange: [DateValueCallback] selected date time changed event/// onConfirm: [DateValueCallback] pressed title confirm widget eventDateTimePickerWidget(
minDateTime: DateTime(2019, 1, 1),
maxDateTime: DateTime(2021, 12, 31),
initDateTime: DateTime(2020, 6, 15),
dateFormat: 'yyyy-MM-dd HH:mm',
locale: DateTimePickerLocale.en_us,
pickerTheme: DateTimePickerTheme.Default,
onChange: (dateTime, selectedIndex) { },
onConfirm: (dateTime, selectedIndex) { },
)
5. DateTimePickerLocale
Support:
en_us: English (EN) United States [Default locale]
ar: Arabic (ar)
ar_eg: Arabic (ar) Egypt
bn: Bengali (BN)
bs: Bosnian (BS)
de: German (DE)
es: Spanish (ES)
fr: French (FR)
hr: Croatian (HR)
hu: Hungarian (HU)
in_id: Bahasa (IN) Indonesia
it: Italian (IT)
jp: Japanese (JP)
ko: Korea (KO)
nl: Dutch (NL)
pt_br: Portuguese (PT) Brazil
ro: Romanian (RO)
ru: Russian (RU)
sr_cyrl: Serbia (sr) Cyrillic
sr_latn: Serbia (sr) Latin
tr: Turkish (TR)
uk: Ukraine (UK)
vi: Vietnamese (VI) Vietnam
zh_cn: Chinese (ZH) Simplified
Add more language
1. Add language i18n file
Fork this project, add language file in lib/src/i18n/ directory, e.g. strings_en_us.dart.
/// English (EN) United Statesclass_StringsEnUsextends_StringsI18n{
const_StringsEnUs();
@overrideStringgetCancelText() {
// TODO return cancel widget's textreturnnull;
}
@overrideStringgetDoneText() {
// TODO return done widget's textreturnnull;
}
@overrideList<String> getMonths() {
// TODO return the array of month's full name [January, February ... December]returnnull;
}
@overrideList<String>? getMonthsShort() {
// TODO return the array of month's short name [Jan, Feb ... Dec]. If return null, will substring the full name (max length is 3)returnnull;
}
@overrideList<String> getWeeksFull() {
// TODO return the array of week's full name [Monday, Tuesday ... Sunday]returnnull;
}
@overrideList<String>? getWeeksShort() {
// TODO return the array of week's short name [Mon, Tue ... Sun]returnnull;
}
}
2. Add Locale
Add language locale in lib/src/i18n/date_picker_i18n.dart file.
enumDateTimePickerLocale {
/// English (EN) United States
en_us,
}
3. Add Locale-Language relationship
Add language-locale relationship in lib/src/i18n/date_picker_i18n.dart file.
All color/style fields are nullable. When you pass a partial theme, missing values are resolved automatically from Theme.of(context), supporting both light and dark mode out of the box.
/// DateTimePicker theme.////// [backgroundColor] DatePicker's background color. null = auto (white / dark surface)./// [cancelTextStyle] Default cancel widget's [TextStyle]. null = auto./// [confirmTextStyle] Default confirm widget's [TextStyle]. null = auto./// [cancel] Custom cancel widget./// [confirm] Custom confirm widget./// [title] Custom title widget. If specify a title widget, the cancel and confirm widgets will not display. Must set [titleHeight] value for custom title widget./// [showTitle] Whether display title widget or not. If set false, the default cancel and confirm widgets will not display, but the custom title widget will display if had specified one custom title widget./// [pickerHeight] The value of DatePicker's height./// [titleHeight] The value of DatePicker's title height./// [itemHeight] The value of DatePicker's column height./// [itemTextStyle] The value of DatePicker's column [TextStyle]. null = auto.constDateTimePickerTheme({
this.backgroundColor,
this.cancelTextStyle,
this.confirmTextStyle,
this.cancel,
this.confirm,
this.title,
this.showTitle = true,
this.pickerHeight = 210.0,
this.titleHeight = 44.0,
this.itemHeight = 36.0,
this.itemTextStyle,
});
Dark Mode
DateTimePickerTheme.of(context) reads Theme.of(context) to produce correct defaults for dark mode. The showDatePicker entry point and all widgets call resolve(context) automatically, so you don't need to do anything — it just works when your app's ThemeData has brightness: Brightness.dark.
If you provide partial overrides, unspecified fields still adapt to the current theme: