2

here I want to validate time. as per this image, when I choose the Shift Begin time and End Time then whenever I am choosing break time it will always between Shift begin time and Shift end time.

Here is the Image of output

enter image description here

Here is the code for the time picker

                       DateTimeField( 
                          decoration: InputDecoration(
                            contentPadding: const EdgeInsets.symmetric(
                                vertical: 15.0, horizontal: 10),
                            labelText: "Time",
                            filled: true,
                            fillColor: Colors.white,
                            border: OutlineInputBorder(
                              borderRadius: new BorderRadius.circular(6),
                            ),
                          ),
                          format: format,
                          onShowPicker: (context, currentValue) async {
                            final time = await showTimePicker(
                              context: context,
                              initialTime: TimeOfDay.fromDateTime(
                                currentValue ?? DateTime.now(),
                              ),
                            );
                            return DateTimeField.convert(time);
                          },
                        ),
alter123
  • 601
  • 2
  • 11
  • 32
Rutvik Gumasana
  • 1,458
  • 11
  • 42
  • 66

1 Answers1

3
  static var startShift = DateTime.now();   
  final endShift = DateTime.now().add(Duration(hours: 8));   
  static var startBreak = startShift.add(Duration(hours: 3));   
  final endBreak = startBreak.add(Duration(hours: 1));

if ((startBreak.isAfter(startShift) && startBreak.isBefore(endShift)) &&
    (endBreak.isAfter(startShift) && endBreak.isBefore(endShift))) {
  //--- Break is within a shift.
} else {
  //--- Invalid break;
}
Rutvik Gumasana
  • 1,458
  • 11
  • 42
  • 66
Anand Kore
  • 1,300
  • 1
  • 15
  • 33