v2.1.0date_time_picker
날짜 또는 시계 대화 상자를 표시하기 위해 날짜 및 시간 양식 필드를 표시하는 Flutter 위젯입니다.
날짜 또는 시계 대화 상자를 표시하기 위한 텍스트 폼 필드를 보여주는 플러터 위젯입니다. 이 위젯은 TextField를 확장하고 TextFormField와 유사한 동작을 합니다.
{"sdk":"flutter"}^0.17.0{"sdk":"flutter"}아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
A Flutter widget to show a text form field to display a date or clock dialog.
This widget extend TextField and has a similar behavior as TextFormField
In the pubspec.yaml of your flutter project, add the following dependency:
dependencies:
...
date_time_picker: "^2.1.0"
In your library add the following import:
import 'package:date_time_picker/date_time_picker.dart';
For help getting started with Flutter, view the online documentation.
There are four presentations for DateTimePicker and can be defined in the type parameter:
DateTimePickerType.date will present a text field with the action tap showing a datePicker dialog box;DateTimePickerType.time will present a text field with the action tap showing a timePicker dialog box;DateTimePickerType.dateTime will present a text field with the action tap showing a datePicker dialog box then a timePicker dialog box;DateTimePickerType.dateTimeSeparated will display two text fields side by side, the first for date and the second for time. Each displaying their respective dialog box, datePicker and timePicker in the tap action;DateTimePicker(
type: date, // options: [date | time | dateTime | dateTimeSeparated], default is date
...
)
initialValue or controller.text can be null, empty or a DateTime string otherwise it will throw an error.
DateTimePicker(
initialValue: '',
firstDate: DateTime(2000),
lastDate: DateTime(2100),
dateLabelText: 'Date',
onChanged: (val) => print(val),
validator: (val) {
print(val);
return null;
},
onSaved: (val) => print(val),
);
More complete example:
DateTimePicker(
type: DateTimePickerType.dateTimeSeparate,
dateMask: 'd MMM, yyyy',
initialValue: DateTime.now().toString(),
firstDate: DateTime(2000),
lastDate: DateTime(2100),
icon: Icon(Icons.event),
dateLabelText: 'Date',
timeLabelText: "Hour",
selectableDayPredicate: (date) {
// Disable weekend days to select from the calendar
if (date.weekday == 6 || date.weekday == 7) {
return false;
}
return true;
},
onChanged: (val) => print(val),
validator: (val) {
print(val);
return null;
},
onSaved: (val) => print(val),
);
The result of val in onChanged, validator and onSaved will be a DateTime String or just a Time String:
Overview