searchPhoneInText function
Implementation
List<String> searchPhoneInText(String text) {
List<String> numbers = [];
String numberFound = '';
bool capturingStarted = false;
for (var i = 0; i < text.length; i++) {
var char = text[i];
bool acceptableChar = false;
try {
if (char == '+') {
} else {
int.parse(char);
}
acceptableChar = true;
} catch (e) {
acceptableChar = false;
}
if (acceptableChar && (i == (text.length - 1))) {
if (capturingStarted) {
numberFound += char;
capturingStarted = false;
if(numberFound.length > 4) {
numbers.add(numberFound);
}
continue;
}
}
if (acceptableChar) {
if (!capturingStarted) {
capturingStarted = true;
}
numberFound += char;
continue;
} else {
if (capturingStarted) {
capturingStarted = false;
if (numberFound.length > 4) {
numbers.add(numberFound);
}
numberFound = '';
continue;
}
}
}
return numbers;
}