<p dir="auto">It is possible to select the date later than the lastDate.<br>
Steps to reproduce:</p>
<ol dir="auto">
<li>create Date picker with firstDate set to today's date e.g. 22/09/2018, lastDate set to 1 year later -&gt; 22/09/2019</li>
<li>showDatePicker, select a later date e.g. 30/09/2018</li>
</ol>
<p dir="auto"><strong>Current behavior:</strong> one can select a date that is later than the lastDate.<br>
<strong>Expected behavior</strong> in such case the date should be set to lastDate.</p>
<p dir="auto">It crashes if done the other way round:<br>
Steps to reproduce:</p>
<ol dir="auto">
<li>create Date picker with firstDate set to today's date e.g. 22/09/2018, lastDate set to 1 year later -&gt; 22/09/2019</li>
<li>showDatePicker, select year 2019 select an earlier date e.g. 15/09/2019</li>
<li>select year 2018 -&gt; crash</li>
</ol>
<p dir="auto">That's because it tries to select 15/09/2018 which is earlier than the firstDate (22/09/2018).</p>
<p dir="auto"><strong>Current behavior:</strong> crash.<br>
<strong>Expected behavior</strong>  in such case the date should be set to firstDate.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="I/flutter ( 7018): The following assertion was thrown building _DatePickerDialog(dirty, state:
I/flutter ( 7018): _DatePickerDialogState#95992):
I/flutter ( 7018): 'package:flutter/src/material/date_picker.dart': Failed assertion: line 503 pos 15:
I/flutter ( 7018): 'selectedDate.isAfter(firstDate) || selectedDate.isAtSameMomentAs(firstDate)': is not true.
I/flutter ( 7018): 
I/flutter ( 7018): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter ( 7018): more information in this error message to help you determine and fix the underlying cause.
I/flutter ( 7018): In either case, please report this assertion by filing a bug on GitHub:
I/flutter ( 7018):   https://github.com/flutter/flutter/issues/new
I/flutter ( 7018): 
I/flutter ( 7018): When the exception was thrown, this was the stack:
I/flutter ( 7018): #2      new MonthPicker (package:flutter/src/material/date_picker.dart:503:15)
I/flutter ( 7018): #3      _DatePickerDialogState._buildPicker (package:flutter/src/material/date_picker.dart:926:20)
I/flutter ( 7018): #4      _DatePickerDialogState.build (package:flutter/src/material/date_picker.dart:952:16)
I/flutter ( 7018): #5      StatefulElement.build (package:flutter/src/widgets/framework.dart:3742:27)
I/flutter ( 7018): #6      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3654:15)
I/flutter ( 7018): #7      Element.rebuild (package:flutter/src/widgets/framework.dart:3507:5)
I/flutter ( 7018): #8      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2255:33)
I/flutter ( 7018): #9      _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding&amp;PaintingBinding&amp;SemanticsBinding&amp;RendererBinding&amp;WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:653:20)
I/flutter ( 7018): #10     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding&amp;PaintingBinding&amp;SemanticsBinding&amp;RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5)
I/flutter ( 7018): #11     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter ( 7018): #12     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter ( 7018): #13     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter ( 7018): #14     _invoke (dart:ui/hooks.dart:128:13)
I/flutter ( 7018): #15     _drawFrame (dart:ui/hooks.dart:117:3)
I/flutter ( 7018): (elided 2 frames from class _AssertionError)"><pre class="notranslate"><code class="notranslate">I/flutter ( 7018): The following assertion was thrown building _DatePickerDialog(dirty, state:
I/flutter ( 7018): _DatePickerDialogState#95992):
I/flutter ( 7018): 'package:flutter/src/material/date_picker.dart': Failed assertion: line 503 pos 15:
I/flutter ( 7018): 'selectedDate.isAfter(firstDate) || selectedDate.isAtSameMomentAs(firstDate)': is not true.
I/flutter ( 7018): 
I/flutter ( 7018): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter ( 7018): more information in this error message to help you determine and fix the underlying cause.
I/flutter ( 7018): In either case, please report this assertion by filing a bug on GitHub:
I/flutter ( 7018):   https://github.com/flutter/flutter/issues/new
I/flutter ( 7018): 
I/flutter ( 7018): When the exception was thrown, this was the stack:
I/flutter ( 7018): #2      new MonthPicker (package:flutter/src/material/date_picker.dart:503:15)
I/flutter ( 7018): #3      _DatePickerDialogState._buildPicker (package:flutter/src/material/date_picker.dart:926:20)
I/flutter ( 7018): #4      _DatePickerDialogState.build (package:flutter/src/material/date_picker.dart:952:16)
I/flutter ( 7018): #5      StatefulElement.build (package:flutter/src/widgets/framework.dart:3742:27)
I/flutter ( 7018): #6      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3654:15)
I/flutter ( 7018): #7      Element.rebuild (package:flutter/src/widgets/framework.dart:3507:5)
I/flutter ( 7018): #8      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2255:33)
I/flutter ( 7018): #9      _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding&amp;PaintingBinding&amp;SemanticsBinding&amp;RendererBinding&amp;WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:653:20)
I/flutter ( 7018): #10     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding&amp;PaintingBinding&amp;SemanticsBinding&amp;RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5)
I/flutter ( 7018): #11     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter ( 7018): #12     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter ( 7018): #13     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter ( 7018): #14     _invoke (dart:ui/hooks.dart:128:13)
I/flutter ( 7018): #15     _drawFrame (dart:ui/hooks.dart:117:3)
I/flutter ( 7018): (elided 2 frames from class _AssertionError)
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt; Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.8.2, on Microsoft Windows [Version 10.0.17134.285], locale en-GB)
[√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[√] Android Studio (version 3.1)
[√] Connected devices (1 available)
&gt; • No issues found!"><pre class="notranslate"><code class="notranslate">&gt; Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.8.2, on Microsoft Windows [Version 10.0.17134.285], locale en-GB)
[√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[√] Android Studio (version 3.1)
[√] Connected devices (1 available)
&gt; • No issues found!
</code></pre></div>
<p dir="auto">DatePicker failed on assertion when I choose past year and selected day-month is before firstDate</p>
<p dir="auto">I have a DatePicker with first and last dates. Lets say from 6-09-2016 to 15-01-2019. Today is 4th May 2018.  I choose year 2016. DatePicker changes only year in selected date. So it wants to show 4-05-2016. But it's out of range. It failed on assertions.</p>
<p dir="auto"><code class="notranslate">Another exception was thrown: 'package:flutter/src/material/date_picker.dart': Failed assertion: line 504 pos 15: 'selectedDate.isAfter(firstDate) || selectedDate.isAtSameMomentAs(firstDate)': is not true. </code></p>
<p dir="auto">It can be fixed as to choose first possible date:<br>
in _YearPickerState build()<br>
<code class="notranslate">onTap: () { DateTime dateTimeYearChanged = new DateTime(year, widget.selectedDate.month, widget.selectedDate.day); if (dateTimeYearChanged.isBefore(widget.firstDate)) { dateTimeYearChanged = widget.firstDate; } widget.onChanged(dateTimeYearChanged); }</code></p>
<p dir="auto">Also, if I choose 2019 year, DatePicker scrolls from month May to month January.  So user doesn't see selected date. But he can press OK and selected date is 4-05-2019, which is out of range. So this is a bug</p>