title: How to split a string on range
body: <p>I new in flutter, and i need your help for something. 
  Can anyone help me how can i write this code line form JavaScript to Flutter: </p>
  
  <pre><code>onInputChange(event, backspace) {
  let newVal = event.replace(/\D/g, '');
  if (backspace &amp;&amp; newVal.length &lt;= 6) {
    newVal = newVal.substring(0, newVal.length - 1);
  }
  if (newVal.length === 0) {
    newVal = '';
  } else if (newVal.length &lt;= 3) {
    newVal = newVal.replace(/^(\d{0,3})/, '($1)');
  } else if (newVal.length &lt;= 6) {
    newVal = newVal.replace(/^(\d{0,3})(\d{0,3})/, '($1) $2'); 
  } else if (newVal.length &lt;= 10) {
    newVal = newVal.replace(/^(\d{0,3})(\d{0,3})(\d{0,4})/, '($1) $2-$3');
  } else {
    newVal = newVal.substring(0, 10);
    newVal = newVal.replace(/^(\d{0,3})(\d{0,3})(\d{0,4})/, '($1) $2-$3');
  }
  this.ngControl.valueAccessor.writeValue(newVal);
  </code></pre>
  
  <p>}</p>
  
  <p>I saw something with .splitMapJoin, but I couldn't do it.</p>