title: Validating Date Field In Flutter with Boolean Data
body: <p>I'm trying to validate a date field in Flutter but, I keep getting this error:</p>
  
  <p>The following assertion was thrown while handling a gesture:
  I/flutter ( 6785): Failed assertion: boolean expression must not be null</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceEvenly,
                                          children: &lt;Widget&gt;[
                                            RaisedButton(
                                              highlightElevation: 8,
                                              color: Colors.white,
                                              shape: RoundedRectangleBorder(
                                                borderRadius:
                                                    BorderRadius.circular(8.0),
                                              ),
                                              child: Text(
                                                selectedYear != null
                                                    ? selectedYear.toString()
                                                    : "Age Checker",
                                                style: TextStyle(
                                                    color: Colors.orange),
                                              ),
                                              onPressed: _showPicker,
                                              
                                            ),
                                            Container(
                                              width: 120,
                                              child: AnimatedBuilder(
                                                animation: animation,
                                                builder: (context, child) =&gt; FormField(
                                                  builder:
                                                      (FormFieldState state) {
                                                    return InputDecorator(
                                                  decoration: InputDecoration(
                                                    labelText:  'You Are '
                                                          "${animation.value.toStringAsFixed(0)}",
                                                    errorText:  state.hasError
                                                            ? state.errorText
                                                            : null,
                                                  ),
                                                  isEmpty: selectedYear == '',
                                                    );
                                                       },  validator: (selectedYear) =&gt; selectedYear ? null: 'rawr',
                                                   
                                                ),
                                                
                                              ),
                                            ),
                                          ],
                                        ),</code></pre>
  </div>
  </div>
  </p>
  
  <p>Here are my methods to help calculate age and validator to validate the age.</p>
  
  <pre><code> void calculateAge() {
  setState(() {
    age = (2018 - selectedYear).toDouble();
  
    animation = Tween&lt;double&gt;(begin: animation.value, end: age).animate(
        CurvedAnimation(
            curve: Curves.fastOutSlowIn, parent: animationController));
  
    animationController.forward(from: 0.0);
  });
  print(age);
  
  if (age &lt; 21){
    ageChecker();
  } else{
  }
  </code></pre>
  
  <p>}</p>
  
  <p>bool isValidDob(String dob) {
    if (dob.isEmpty) return true;</p>
  
  <p>}</p>
  
  <p>I want to confirm the user is over 21 prior to moving on to the next screen. Please let me know where I went wrong.</p>