Tasks
This commit is contained in:
parent
77518ee235
commit
f113dce453
|
|
@ -6,14 +6,14 @@ class TimePicker extends StatefulWidget {
|
|||
Key key,
|
||||
@required this.labelText,
|
||||
@required this.onSelected,
|
||||
@required this.timeOfDay,
|
||||
@required this.selectedDate,
|
||||
this.validator,
|
||||
this.autoValidate = false,
|
||||
}) : super(key: key);
|
||||
|
||||
final String labelText;
|
||||
final TimeOfDay timeOfDay;
|
||||
final Function(TimeOfDay) onSelected;
|
||||
final DateTime selectedDate;
|
||||
final Function(DateTime) onSelected;
|
||||
final Function validator;
|
||||
final bool autoValidate;
|
||||
|
||||
|
|
@ -26,9 +26,9 @@ class _TimePickerState extends State<TimePicker> {
|
|||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
if (widget.timeOfDay != null) {
|
||||
if (widget.selectedDate != null) {
|
||||
_textController.text = formatDate(
|
||||
convertTimeOfDayToDateTime(widget.timeOfDay).toIso8601String(), context,
|
||||
widget.selectedDate.toIso8601String(), context,
|
||||
showDate: false, showTime: true);
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ class _TimePickerState extends State<TimePicker> {
|
|||
}
|
||||
|
||||
void _showDatePicker() async {
|
||||
final selectedDate = widget.timeOfDay;
|
||||
final selectedDate = widget.selectedDate;
|
||||
final now = DateTime.now();
|
||||
|
||||
final hour = selectedDate?.hour ?? now.hour;
|
||||
|
|
@ -52,11 +52,11 @@ class _TimePickerState extends State<TimePicker> {
|
|||
context: context, initialTime: TimeOfDay(hour: hour, minute: minute));
|
||||
|
||||
if (selectedTime != null) {
|
||||
_textController.text = formatDate(
|
||||
convertTimeOfDayToDateTime(selectedTime).toIso8601String(), context,
|
||||
final dateTime = convertTimeOfDayToDateTime(selectedTime);
|
||||
_textController.text = formatDate(dateTime.toIso8601String(), context,
|
||||
showTime: true, showDate: false);
|
||||
|
||||
widget.onSelected(selectedTime);
|
||||
widget.onSelected(dateTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -101,8 +101,8 @@ class TimeEditDetails extends StatefulWidget {
|
|||
|
||||
class TimeEditDetailsState extends State<TimeEditDetails> {
|
||||
String _date;
|
||||
TimeOfDay _startTime;
|
||||
TimeOfDay _endTime;
|
||||
DateTime _startDate;
|
||||
DateTime _endDate;
|
||||
|
||||
final _durationController = TextEditingController();
|
||||
|
||||
|
|
@ -113,9 +113,9 @@ class TimeEditDetailsState extends State<TimeEditDetails> {
|
|||
final endDate = taskTime.endDate;
|
||||
|
||||
_date = startDate.toIso8601String();
|
||||
_startTime = TimeOfDay(hour: startDate.hour, minute: startDate.minute);
|
||||
_startDate = startDate;
|
||||
if (endDate != null) {
|
||||
_endTime = TimeOfDay(hour: endDate.hour, minute: endDate.minute);
|
||||
_endDate = endDate;
|
||||
_durationController.text = formatDuration(taskTime.duration);
|
||||
}
|
||||
|
||||
|
|
@ -167,13 +167,13 @@ class TimeEditDetailsState extends State<TimeEditDetails> {
|
|||
date.year,
|
||||
date.month,
|
||||
date.day,
|
||||
_startTime.hour,
|
||||
_startTime.minute,
|
||||
_startDate.hour,
|
||||
_startDate.minute,
|
||||
widget.taskTime.startDate.second)
|
||||
.toUtc(),
|
||||
endDate: _endTime != null
|
||||
endDate: _endDate != null
|
||||
? DateTime(date.year, date.month, date.day,
|
||||
_endTime.hour, _endTime.minute)
|
||||
_endDate.hour, _endDate.minute)
|
||||
.toUtc()
|
||||
: null,
|
||||
);
|
||||
|
|
@ -191,14 +191,14 @@ class TimeEditDetailsState extends State<TimeEditDetails> {
|
|||
),
|
||||
TimePicker(
|
||||
labelText: localization.startTime,
|
||||
timeOfDay: _startTime,
|
||||
onSelected: (timeOfDay) => _startTime = timeOfDay,
|
||||
selectedDate: _startDate,
|
||||
onSelected: (timeOfDay) => _startDate = timeOfDay,
|
||||
),
|
||||
TimePicker(
|
||||
key: ValueKey(_endTime),
|
||||
key: ValueKey(_endDate),
|
||||
labelText: localization.endTime,
|
||||
timeOfDay: _endTime,
|
||||
onSelected: (timeOfDay) => _endTime = timeOfDay,
|
||||
selectedDate: _endDate,
|
||||
onSelected: (timeOfDay) => _endDate = timeOfDay,
|
||||
),
|
||||
PopupMenuButton<int>(
|
||||
padding: EdgeInsets.zero,
|
||||
|
|
@ -216,9 +216,9 @@ class TimeEditDetailsState extends State<TimeEditDetails> {
|
|||
setState(() {
|
||||
_durationController.text =
|
||||
formatDuration(Duration(minutes: minutes));
|
||||
final dateTime = convertTimeOfDayToDateTime(_startTime)
|
||||
final dateTime = _startDate
|
||||
.add(Duration(minutes: minutes));
|
||||
_endTime = convertDateTimeToTimeOfDay(dateTime);
|
||||
_endDate = dateTime;
|
||||
});
|
||||
},
|
||||
child: InkWell(
|
||||
|
|
|
|||
|
|
@ -248,7 +248,7 @@ String formatDate(String value, BuildContext context,
|
|||
if (showTime) {
|
||||
String format;
|
||||
if (!showDate) {
|
||||
format = company.enableMilitaryTime ? 'H:mm' : 'h:mm a';
|
||||
format = company.enableMilitaryTime ? 'H:mm:ss' : 'h:mm:ss a';
|
||||
} else {
|
||||
final dateFormats = state.staticState.datetimeFormatMap;
|
||||
final dateFormatId = company.datetimeFormatId > 0
|
||||
|
|
@ -256,7 +256,7 @@ String formatDate(String value, BuildContext context,
|
|||
: kDefaultDateTimeFormat;
|
||||
format = dateFormats[dateFormatId].format;
|
||||
if (company.enableMilitaryTime) {
|
||||
format = format.replaceFirst('h:mm a', 'H:mm');
|
||||
format = format.replaceFirst('h:mm:ss a', 'H:mm:ss');
|
||||
}
|
||||
}
|
||||
final formatter = DateFormat(format, localeSelector(state));
|
||||
|
|
|
|||
Loading…
Reference in New Issue