title: Flutter TextField input validation for a date
body: <p>I am trying to write a date input control which accepts a date like 23/12/1997. What I would like it to do is automatically insert the / characters for the user. So as they type in 23 the listener returns 23/, so that they can then type in 12. At this point the listener again adds a / leaving the user to complete the date by typing 1997.
  My TextEditingController code half works and looks like this:</p>
  
  <pre><code>final _controller = TextEditingController();
  </code></pre>
  
  <pre><code>_controller.addListener(() {
        String text = _controller.text;
        if (text.length == 2) {
          text += '/';
        }
        if (text.length == 5) {
          text += '/';
        }
        _controller.value = _controller.value.copyWith(
          text: text,
          selection:
              TextSelection(baseOffset: text.length, extentOffset: text.length),
          composing: TextRange.empty,
        );
        print(_controller.text);
      }
  </code></pre>
  
  <p>So it works fine until the user makes a mistake and needs to backtrack. As soon as a / is deleted it is immediately replaced stopping any further editing of the date. </p>
  
  <p>In order to get it to work I need to access is the previously entered text to determine if the user is backspacing. So if <code>text == 23/ &amp;&amp; previous_text == 23/1</code> then I can remove the / from text.</p>
  
  <p>I found this question <a href="https://stackoverflow.com/questions/55631224/flutter-textfield-input-only-decimal-numbers">textfield must only accept numbers</a> and I think it may help me, but I am not sure how to implement an existing widget and override its methods. Of course there may be a simpler way to do this within the TextEditingController?</p>