Skip to content

Instantly share code, notes, and snippets.

@Dviejopomata
Created February 26, 2020 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dviejopomata/3cfc1bda54bdb2b34f647f7da1b7575b to your computer and use it in GitHub Desktop.
Save Dviejopomata/3cfc1bda54bdb2b34f647f7da1b7575b to your computer and use it in GitHub Desktop.
Extraer tarjeta en flutter
final String creditPattern = r"(\d{4}) (\d{4}) (\d{4}) (\d{4})";
final RegExp cardRegexp = RegExp(creditPattern);
final expPattern = r"(\d{2})\/(\d{2})";
final expRegexp = RegExp(expPattern);
final VisionText visionText =
await textRecognizer.processImage(visionImage);
for (TextBlock block in visionText.blocks) {
for (TextLine line in block.lines) {
if (cardRegexp.hasMatch(line.text)) {
setState(() {
tarjetaCredito = line.text;
});
}
if (expRegexp.hasMatch(line.text)) {
final allMatches = expRegexp.firstMatch(line.text);
final month = int.parse(allMatches.group(1));
final year = int.parse(allMatches.group(2));
setState(() {
expMonth = month;
expYear = year;
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment