title: Flutter Datepicker validation - how to solve the problem
body: <p>In my class I have a date range picker and I have other fields I have used Form validation is working for other fields but I don't know how to declare the validation when the user submits the form if the dates are not chosen it should display the error like choose date.</p>
  <p>Also, I wanted to check: let's say I have two class in main class I have declared the form and in sub class also I have declared but in second class I don't have button but in main class I have button how to refer?</p>
  <p><strong>Display the date choosen or else it will display the default text:</strong></p>
  <pre><code>String _displayText(String begin, DateTime? date) {
      if (date != null) {
        return '$begin Date: ${date.toString().split(' ')[0]}';
      } else {
        return 'Press the button to show the picker';
      }
    }
  </code></pre>
  <p><strong>Text will display:</strong></p>
  <pre><code> Text(
                                    _displayText('Start', startdate),
                                    style: const TextStyle(
                                        fontWeight: FontWeight.bold,
                                        fontSize: 15,
                                        color: Colors.black),
                                  ),
  </code></pre>
  <p><strong>ShowDateRangepicker</strong></p>
  <pre><code>void _show() async {
      final DateTimeRange? result = await showDateRangePicker(
        context: context,
        firstDate: DateTime(DateTime.now().year - 10),
        lastDate: DateTime(DateTime.now().year + 10),
        currentDate: DateTime.now(),
        saveText: 'Done.',
      );
  
      if (result != null) {
        setState(() {
          print(result.start);
          startdate = result.start;
          enddate = result.end;
          _selectedDateRange = result;
        });
      }
    }
  </code></pre>