Reputation: 91
I want the time change into 12 hours format. Here's my code:
TextButton(
onPressed: () {
FocusScope.of(context).unfocus();
DatePicker.showDateTimePicker(
context,
showTitleActions: true,
onConfirm: widget.onChangeDateSched,
locale: LocaleType.en,
);
},
Upvotes: 0
Views: 526
Reputation: 12595
you can try with this package flutter_datetime_picker
TextButton(
child: Text("Time Pick"),
onPressed: ()
{
FocusScope.of(context).unfocus();
DatePicker.showTime12hPicker(
context,
showTitleActions: true,
locale: LocaleType.en,
);
}
)
output:
For both date and time use this package date_time_picker and initialize the date formatting
initializeDateFormatting('en');
TextButton(
child: DateTimePicker(
locale: Locale('en'),
type: DateTimePickerType.dateTimeSeparate,
dateMask: 'yyyy-MM-dd',
initialValue: DateTime.now().toString(),
firstDate: DateTime(2000),
lastDate: DateTime.now(),
icon: Icon(Icons.event),
use24HourFormat: false,
dateLabelText: 'Date',
timeLabelText: "Hour",
onChanged: (val) {
print(val);
},
),
)
Upvotes: 2
Reputation: 971
DatePicker.showTime12hPicker(
context,
showTitleActions: true,
locale: LocaleType.en,
currentTime: DateTime.now()
);
Upvotes: 0
Reputation: 684
you may use
final format = DateFormat("HH:mm");
to sort out your issue..
Upvotes: 1